From patchwork Tue Jun 18 15:10:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13702516 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBAC7C27C4F for ; Tue, 18 Jun 2024 15:21:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5CAC66B0306; Tue, 18 Jun 2024 11:21:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 579A06B0307; Tue, 18 Jun 2024 11:21:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4688C6B0308; Tue, 18 Jun 2024 11:21:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 28DE36B0306 for ; Tue, 18 Jun 2024 11:21:21 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5DB4B8175F for ; Tue, 18 Jun 2024 15:10:39 +0000 (UTC) X-FDA: 82244346198.04.DE7354F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 4FEBC18001E for ; Tue, 18 Jun 2024 15:10:37 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HuKEzLwf; spf=pass (imf16.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718723428; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=1es3ECOkdNs+2hzIuvv3Jx9YKFXHOd3EXF7iaYcF0ds=; b=7AZx4wEhC3shIf0U2iK1YiDmfmUshSMibo2HLWJJ+2MkxrJ9aIseDA1FCdU98YC0bgPncZ CV1pEhsLcTxB89s2/ghvqK57M3yIn2NsZUWR6OV39zUWY/VD1ENHhFZozl4a+nLmWBPT4i HyzNV+23TOAxIMpzozItkh9+se+KcSU= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HuKEzLwf; spf=pass (imf16.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718723428; a=rsa-sha256; cv=none; b=IHY3fALakqEoD5eFu5bDYNWA9uXutAyOiLOblpWRrvU37Uy2PPCiVUM1tP+215tI0Mwy+x QcJPfE6kHBBZsuT/vtOo7n3wyqzAHfPDJ+P9rzCqJee012fOPHLUQlnfeQCQFM+ts7i2Yv jckIcwtMJbMNYByxrMj/F3+DaMaXJIY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718723436; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=1es3ECOkdNs+2hzIuvv3Jx9YKFXHOd3EXF7iaYcF0ds=; b=HuKEzLwfmqZTdsQ1VBLUfCzqcEst2YtCKlr9CWIzed1uVBdneIfRHJ7XyBEf1Vm6om0KMA Gl/cM5O1L8zl9bdYjC8B8EzR1Ifdbxvguy2Isq9ZHPvYSFdYYOJSW2bMj0Km2p2wpJ87JJ ahPArJ5Z6i7Vps9+MXVjXJucYRAzgtY= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-657-1udAHGKsNN68fESFhGYFag-1; Tue, 18 Jun 2024 11:10:31 -0400 X-MC-Unique: 1udAHGKsNN68fESFhGYFag-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8B95C19560B1; Tue, 18 Jun 2024 15:10:30 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.208]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 67D8D1956057; Tue, 18 Jun 2024 15:10:28 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Yosry Ahmed Subject: [PATCH v1] mm/rmap: cleanup partially-mapped handling in __folio_remove_rmap() Date: Tue, 18 Jun 2024 17:10:26 +0200 Message-ID: <20240618151026.521019-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 4FEBC18001E X-Stat-Signature: mx1pfk7wr7yct71mjhmeqckwriiyhwr4 X-Rspam-User: X-HE-Tag: 1718723437-358571 X-HE-Meta: U2FsdGVkX1/qYEfZksu+WzR6XFbDCrfzvtKORAOmDUcpOrYtdmb8wnQIAqHcKYDJ8q3FAw86DK0XM2SukNXduv2aCNz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Nxy82sEUAlbfjF8vtzvy8dOjjMtGhWao5uJX8/KiKItlGCu20UriRDagNBo02EUAUwBsPg99aSqtX8NQS4E78gTzZhWd4mkyRmP7dVaQTimIGBzAxP24dlP7S1vCKR4iUsLhjcatDRDBXDyTq4pVQ+udUmV1bXjZsv7ExzqGVLdGPnAn1gpKfmft5WSPe0Nf5ETuZK7jIfcTto66xges0z9Xc4uMsYA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Let's simplify and reduce code indentation. In the RMAP_LEVEL_PTE case, we already check for nr when computing partially_mapped. For RMAP_LEVEL_PMD, it's a bit more confusing. Likely, we don't need the "nr" check, but we could have "nr < nr_pmdmapped" also if we stumbled into the "/* Raced ahead of another remove and an add? */" case. So let's simply move the nr check in there. Note that partially_mapped is always false for small folios. No functional change intended. Cc: Yosry Ahmed Signed-off-by: David Hildenbrand Reviewed-by: Yosry Ahmed --- mm/rmap.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index afec4b6800caf..aa900e46cdf82 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1551,11 +1551,12 @@ static __always_inline void __folio_remove_rmap(struct folio *folio, } } - partially_mapped = nr < nr_pmdmapped; + partially_mapped = nr && nr < nr_pmdmapped; break; } - if (nr) { + if (partially_mapped && folio_test_anon(folio) && + list_empty(&folio->_deferred_list)) /* * Queue anon large folio for deferred split if at least one * page of the folio is unmapped and at least one page @@ -1563,10 +1564,7 @@ static __always_inline void __folio_remove_rmap(struct folio *folio, * * Check partially_mapped first to ensure it is a large folio. */ - if (folio_test_anon(folio) && partially_mapped && - list_empty(&folio->_deferred_list)) - deferred_split_folio(folio); - } + deferred_split_folio(folio); __folio_mod_stat(folio, -nr, -nr_pmdmapped); /*