From patchwork Mon Mar 25 17:14:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13602533 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 ED27CC54E64 for ; Mon, 25 Mar 2024 17:14:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E9B36B0096; Mon, 25 Mar 2024 13:14:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 772716B0098; Mon, 25 Mar 2024 13:14:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C79F6B0099; Mon, 25 Mar 2024 13:14:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3FE916B0096 for ; Mon, 25 Mar 2024 13:14:19 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 107D51C0111 for ; Mon, 25 Mar 2024 17:14:19 +0000 (UTC) X-FDA: 81936209838.07.6E27B09 Received: from mail-il1-f169.google.com (mail-il1-f169.google.com [209.85.166.169]) by imf06.hostedemail.com (Postfix) with ESMTP id 39CBA18000F for ; Mon, 25 Mar 2024 17:14:17 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ftu7dtsJ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.166.169 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711386857; a=rsa-sha256; cv=none; b=m8keoP1MKLmY9cCBfCJHCe/COVPDFqKnvj9Y12NF66DCqtXQew0MoZ8gvdxiTevZYFgmTv vDj+cy2iC0ZTOJXd7VzlBabN4b/o/WyjHjNLp1r1NUET7iMxdNOrIvS/j+h+0pnii6NF/u OVQCQ0rDfUy2cj9K3Aj5fO/TXj72Aaw= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ftu7dtsJ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.166.169 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711386857; 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=bN9a48YnOEXH7sPm0Ke4Oa5WKVmRd1RkDjnQJHDaF+o=; b=oiss4mr1qZoSjHoBn4vW8OGNQsIDf4AFEjQ44PpxcEtf7qePzBEUULD6SDpHaXn/nSLk7D 4ofHaNmwwc/iTh0NmX5k7Hxz4T8V68DZQTLXpFa6jkFtAIt/bmZ1x0QHMLKAv7SyMVvtdS Y8Wsz/kcEbzMYlUM3EMNMutCXYSYorA= Received: by mail-il1-f169.google.com with SMTP id e9e14a558f8ab-3684faf6286so19499945ab.1 for ; Mon, 25 Mar 2024 10:14:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711386855; x=1711991655; 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=bN9a48YnOEXH7sPm0Ke4Oa5WKVmRd1RkDjnQJHDaF+o=; b=Ftu7dtsJqZ5Q+1wguhd4Qrj4foBe9eur9+ADNhIVUYNHEf+RcENvYBWsx4YpSPpsqU IGzhX4McmOm2hNRp6S+M5n3QKDtYy26MMZQpRMXnRUJ87iGBWL6v1jGJUiIBpzRsKk4p 0gN1o06QdzcP3RUkvkKhT2E1Fjzob4exm2kFZ+x2HzIhNPTe1dyShcIGilgO36SBFV0v ntGsFE7UOPJKVJdCAAZnnVeYPUi4/evzJ2U1lJZAKfWALrULSIrQaaNwb1UIfoS6zqij iWvtq7zf8RwqoHrUhyjqHWmQm3pXbOE89T1tuP9boWamvW12o28qwFA9dDFcYLVt4aKH JFag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711386855; x=1711991655; 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=bN9a48YnOEXH7sPm0Ke4Oa5WKVmRd1RkDjnQJHDaF+o=; b=k2X+DcFUyKxJW+yviidl162aMq96jrZyyOE4vQWGzP2lDllogixchsxA410kRNYMeI YBLzEEUxxKdCgbFkUnP5dRkXfzqtHFZb5WOzUFJaZhqfDIt8QJ6Yv/M/93PUIJrPTZXH DlXmqB3BwcI6GijrJO09hZpT4QbX/dWR0fp3v4KOa66f0WHkbSiKjbwUfY2R/Rayrvz9 HdYU9DiU/McQCnKR14hrinv8Ll2Z+F7ElRd19LM03w7WFZZRk7xNGZNRfMxrwSfWttk+ rElov4vcJiexhWFOwXnmtTZWxxitGc04/HCkXwytK6TAwCJKsqsz8XyRJFMCr8wpDsH9 9jUw== X-Gm-Message-State: AOJu0YxW06e5M9bTZMkbw61uFAZG56CUBzkph44l4zrNSF+b4e77n/HV CEjtNrulp35R0CCSq0lb+n6gZGIT8SivRc7nyUuFzf48Geqqj1FHgPhRJceTojA+ULFc X-Google-Smtp-Source: AGHT+IEV6m/IQGGduQkAd1EXsYeOBd+/asYh5Dr5GFoEqy3C5fYnTIRwAYULWlk6rk/10OQ+ts/pmA== X-Received: by 2002:a92:c883:0:b0:368:4a8f:85f5 with SMTP id w3-20020a92c883000000b003684a8f85f5mr7282293ilo.19.1711386855551; Mon, 25 Mar 2024 10:14:15 -0700 (PDT) Received: from KASONG-MB2.tencent.com ([115.171.40.106]) by smtp.gmail.com with ESMTPSA id r16-20020a63d910000000b005dc5129ba9dsm6001812pgg.72.2024.03.25.10.14.13 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 25 Mar 2024 10:14:15 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Matthew Wilcox , Andrew Morton , linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH v2 2/4] mm/filemap: clean up hugetlb exclusion code Date: Tue, 26 Mar 2024 01:14:03 +0800 Message-ID: <20240325171405.99971-3-ryncsn@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325171405.99971-1-ryncsn@gmail.com> References: <20240325171405.99971-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 39CBA18000F X-Stat-Signature: jah66ko78z1senq38tyhqdde7fhaoyj6 X-HE-Tag: 1711386857-602783 X-HE-Meta: U2FsdGVkX19vvoeY2j+zE1cIqmcStjWWz45X15arwBr2qsrI0GQHI1tSi8cfy8Uoyz6T5PSECLZwvTOq3eRuYU1d8mLsD6lniyKXc89MrsmVgd2FjP/yKMIQYMbTZ6I1HnOyy+hlpWL96u3TD50bL57k+iNz5oCY+SEZpWhUNyVFSGbz+YJzoXOww1Yg+XhvconYnUHNSKgvt+UedcJPp1q0MR3L0CinZghG1OzR17fa5v/1Rk528aA7BzFdSmQ3hlB1wH3vKcEVEHGo/YOBm/xkO/YK4gW6Oa4it6A2+zmd2KY/dejLQBs7/p1IPIUyV1uHAHFsdh8rnNl5Rl6i0FUXzXoEgdS7bqAn1Fl4guA8OgBPGPW0QerpS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zdNv8R2pxG57DMPQcNMbcGnjIWATpeRaHNe1BaxSAjCGnLgk4qlWwsVz/JXsdiejYVM31KVGnejii0lYYN9tt6qxeDGUVZz34OLHsBwMaLNZVP0myS4wicW6ud8BPsbsfhw+k44MFWvhNvIhd7voH40BFU58yC7RxBBSfltLsRfK7l6ay+h8onQ0LT3CrRlPchUuXw67CgMgsT2RxMRWcRV0c+Hv7h2o6308Og== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000940, 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