From patchwork Tue Mar 19 09:27:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13596501 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 D9F86C54E5D for ; Tue, 19 Mar 2024 09:41:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 718A36B008C; Tue, 19 Mar 2024 05:41:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 67B516B0092; Tue, 19 Mar 2024 05:41:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 432956B0093; Tue, 19 Mar 2024 05:41:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 1E5366B008C for ; Tue, 19 Mar 2024 05:41:48 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B87D31C0EEC for ; Tue, 19 Mar 2024 09:41:47 +0000 (UTC) X-FDA: 81913296654.01.49F26FC Received: from mail-oi1-f170.google.com (mail-oi1-f170.google.com [209.85.167.170]) by imf26.hostedemail.com (Postfix) with ESMTP id E596A140007 for ; Tue, 19 Mar 2024 09:41:45 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=D0lwQSmS; spf=pass (imf26.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.167.170 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710841305; a=rsa-sha256; cv=none; b=4dgaHaGjQa8tcL4LJhVEKDiGvI2b0+hUP7SKylf8awn5epZcEmjZsbJye7+qK4rT7cZgIT W9ImFLRVTxJh4MHDkQ8J1o83rLQ83RVG47QSBJWoJu5Si2nN0lmpMQYsmIt51u5E/Cdpgh pOTtClLXtpTfpbFXASkEdGmLbPAWJt8= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=D0lwQSmS; spf=pass (imf26.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.167.170 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710841305; h=from:from:sender:reply-to: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:in-reply-to:references:references:dkim-signature; bh=J34Qf2qKoII5Mgpe9QZtGvKa+BRn934GAZXO0p+CcPY=; b=7QDzKhgpmv2I1z6gxwYPyKJLXUjoDzJqenu2tWEFdrz7IygPUzYF5kLggj0DnkQ1WZTnvx 1hBxgS1Wq0P172E6K5e8gGml2xpIJ1/qbi0z2SwjrNrhlrOFymhxWj+KyU/vip8PfnzYQw qTNu7S7QMSrIUOr7xQnzDrMP0fHpfLM= Received: by mail-oi1-f170.google.com with SMTP id 5614622812f47-3c387e02f23so976445b6e.3 for ; Tue, 19 Mar 2024 02:41:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710841304; x=1711446104; darn=kvack.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=J34Qf2qKoII5Mgpe9QZtGvKa+BRn934GAZXO0p+CcPY=; b=D0lwQSmSQZ1DFuVvJ044XFc0Mln3Kr++fd7dSB+hDlKxR1snGD1iH2PFcT8EYmwkxY Dv4pPlta2nmm8g3cFNHlgbP+CSb3/wip6FaoWT8lrzglW0jTV6o9FaP9G/AUR5LHgW0b NuKWl6vknNpBkZQvDf4ruXi6+M45gwi1RJdurp2y3hE9DJSDdY4PGx/fngDPyNPyqGkH EbYc5vxU2WTdEDUMNhS4f3ieG8iOuJdJ4mmg/EdkuXwNKFtH2KHGhs7BCvhChgfX9S12 nL92Wpq7lytEx5Wl8osyy1y9aGUTFIvBIQHxt7lDqLe8URCcIxnOyI8qm7g2UaI5Diz3 KATg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710841304; x=1711446104; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=J34Qf2qKoII5Mgpe9QZtGvKa+BRn934GAZXO0p+CcPY=; b=QCFCS6SsFevZIN05pSmiDdJ4OsRvdualzQ5G3t9xTsUuqnlyg6HJwyo1ob7Z8sXMSb wYi5lgrQ28tzoQsE9FTcdP59O3XYRXs3nxIEHqIaQfdTbJBFjN5FQir98hL2WmZvembg SYd6Nh427gbC2j48FNmCM3PZHNaXeWfxjQ70iSbUWat0W9pgeriDSY7OJhvCDEsdc9Bf xZDY6U/dKkb0potcCG53x093dM/gCck2BO+STxhVSvW1x2o3S8Zn3uqnrUKnToA/UXQJ K0nKfnc4k7jM5ccxpGM14Yo8jDRBLNz/YHsf+gHvsBff8xXBsUJCRM38npN+7y4pOjoy Zl6A== X-Gm-Message-State: AOJu0Yw/j9tXIGMYS1qAITEE8nGBcxAmTJqt+eVtFXfrbFSlxwJ9WjGO BqM4MkMcQNF9xkBr39FAkMTdc6+3upwNf053wBI7jjZfkYHFmFmlWqVOCZpaiPTYUU6b X-Google-Smtp-Source: AGHT+IEJHFnNbXQdn3Vy4EOryeIqwhnOxZinPVrn7nSGg3zBBB2/OolNOe72ReevQN6mJSPYvWaGpA== X-Received: by 2002:a05:6808:81:b0:3c2:616a:22 with SMTP id s1-20020a056808008100b003c2616a0022mr12406922oic.55.1710841304361; Tue, 19 Mar 2024 02:41:44 -0700 (PDT) Received: from KASONG-MB2.tencent.com ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id i185-20020a62c1c2000000b006e583a649b4sm9708761pfg.210.2024.03.19.02.41.42 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 19 Mar 2024 02:41:43 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , Matthew Wilcox , linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH 2/4] mm/filemap: clean up hugetlb exclusion code Date: Tue, 19 Mar 2024 17:27:31 +0800 Message-ID: <20240319092733.4501-3-ryncsn@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240319092733.4501-1-ryncsn@gmail.com> References: <20240319092733.4501-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: E596A140007 X-Stat-Signature: 3z14z4po44hjyskkfet4hntoyf9wnxbn X-Rspam-User: X-HE-Tag: 1710841305-855167 X-HE-Meta: U2FsdGVkX187t53BhA0X9HjIjviaPXEgKyg1IWoPVAsIzniIl0ATuSYOR8drUqXa0YyYkLqmjKZHwEtiBEAKkSoyfdEDlHHASa3wHdDWdDrxjtVDGn9iJxHOCxTnUk426q+h5ToSTJHrytVVHRXIm3/5BT40mOcBysE2UgXKK4/z+63tWEcmYIKVtinxcjLNQxtcxDXXvqqLcwwi9kjW4NKwI3SRjRfWamTfFa9CtBO/3Cu02hEbcK3RtUXUiUAe4oglyK7RlNEauPiWMeDQi7nMHiiiSiMYWpPpDCWQd4AnIx+02rWb3Mg49BU0r8wGeUrSgDu/mYSpNFMCxSxh0eSPIlM3vmz3LffouzBE/9z8BYPzXERqFVNc7BnA2WoUIFPxc/s77IvLTa7+M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MZcnLw363dP1fPU8XllotRBo/WCUPQ1xWFfTg2enAa97CgkTmOEf7cpYmJsu0yNodXSAtPwviy9z36py3QO9pDQbHFDzlJepbtts0EYmSPCv2CPnxaCUPB63qf9nYf7Dqcg1fYaF+uWkz/yfup+vA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Kairui Song __filemap_add_folio only has two callers, one never passes hugetlb folio and one always passes in hugetlb folio. So move the hugetlb related cgroup charging out of it to make the code cleaner. Signed-off-by: Kairui Song Acked-by: Matthew Wilcox (Oracle) --- mm/filemap.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index f07ea0b97698..6bbec8783793 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -853,20 +853,12 @@ noinline int __filemap_add_folio(struct address_space *mapping, { XA_STATE(xas, &mapping->i_pages, index); bool huge = folio_test_hugetlb(folio); - bool charged = false; - long nr = 1; + long nr; VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); VM_BUG_ON_FOLIO(folio_test_swapbacked(folio), folio); mapping_set_update(&xas, mapping); - if (!huge) { - int error = mem_cgroup_charge(folio, NULL, gfp); - if (error) - return error; - charged = true; - } - VM_BUG_ON_FOLIO(index & (folio_nr_pages(folio) - 1), folio); xas_set_order(&xas, index, folio_order(folio)); nr = folio_nr_pages(folio); @@ -931,8 +923,6 @@ noinline int __filemap_add_folio(struct address_space *mapping, trace_mm_filemap_add_to_page_cache(folio); return 0; error: - if (charged) - mem_cgroup_uncharge(folio); folio->mapping = NULL; /* Leave page->index set: truncation relies upon it */ folio_put_refs(folio, nr); @@ -946,11 +936,16 @@ int filemap_add_folio(struct address_space *mapping, struct folio *folio, void *shadow = NULL; int ret; + ret = mem_cgroup_charge(folio, NULL, gfp); + if (ret) + return ret; + __folio_set_locked(folio); ret = __filemap_add_folio(mapping, folio, index, gfp, &shadow); - if (unlikely(ret)) + if (unlikely(ret)) { + mem_cgroup_uncharge(folio); __folio_clear_locked(folio); - else { + } else { /* * The folio might have been evicted from cache only * recently, in which case it should be activated like