From patchwork Mon Apr 15 17:18:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13630433 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 A0B98C4345F for ; Mon, 15 Apr 2024 17:19:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9D76F6B00A1; Mon, 15 Apr 2024 13:19:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 938416B00A3; Mon, 15 Apr 2024 13:19:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B1DE6B00A5; Mon, 15 Apr 2024 13:19:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 522856B00A1 for ; Mon, 15 Apr 2024 13:19:20 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E08EC8071F for ; Mon, 15 Apr 2024 17:19:19 +0000 (UTC) X-FDA: 82012427238.30.E2D69F4 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by imf06.hostedemail.com (Postfix) with ESMTP id 137A618000D for ; Mon, 15 Apr 2024 17:19:17 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=VARa2z3w; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.216.42 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713201558; a=rsa-sha256; cv=none; b=47HN757w9xT2mXsFJCKCeYwPecCG6Z866uvpkwoM/Xf/acnYDR+ex3BCAO5yVEqNMFAzIB vsuq/VCPA5mf1vilBbKu+w4NdYyXj047IliCDJkBwlh9MWWbHFP2L1FNvhLlaP+hlZ6QPa 0bvMzsTc7dVmDa/edQXE7Sdt3o+2JTc= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=VARa2z3w; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.216.42 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=1713201558; 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=x5lu4xKhCQ/0haQPCj7eyNWwUk1BrbeMvC9dF21zPVk=; b=uBavVAPblHDzynKbwRUfa1NlqTvjlnkXn9BCWy7jeP2z8z0BEg4rtoVHRqdaAuJZK11gmB AuEGB+hVZYivzJjksHD1JZ0/1T8FBPrMheEMVnVPuNFIhil9ZN4+RXLR4b6GuCPI3NXmIT lylM95rxBlhie1CxTwJQbF7kTP5egRs= Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-2a536b08d63so2015330a91.1 for ; Mon, 15 Apr 2024 10:19:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713201556; x=1713806356; 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=x5lu4xKhCQ/0haQPCj7eyNWwUk1BrbeMvC9dF21zPVk=; b=VARa2z3wMK0bHW4vgwWuOydk7ikolRu6OprrcY4R6kUYzjaBPNIXIOt/E5gkdVyklA zQCPFO9fVFxjNSYm3PZJZ9nTHNa4+crzICcmSYVaW1HTd7MWShTI1qa/F24z8cPn/A1i M9TscpyQ5awqxMgQ+TXE9bbVORGGSporAEtIbkl1pWqWCC3KYo2y1O8u1x10M1mZb2dO Kk+Fsj0m4mQNroOJXuzfuU4c3psTJSAOvg4ogmPYseYm3vPbkvgvqhTkLM0x+4tGFGjH hoWfNcT44CQv6HPUsUi50AI/4BZ6deywlYBuvE4xKylKg+XG0FTyj+ozmir13upK3cuF iQAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713201556; x=1713806356; 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=x5lu4xKhCQ/0haQPCj7eyNWwUk1BrbeMvC9dF21zPVk=; b=LZo3phV3Qwmj7jROiGxkArZfzn8HD1/J5hss2H8u+3yEJzqLofMrRc1uIsiWGxJHJC ZuCzV4xGbdfVWd4YB3/H98ZDJO//xDOPSrRDYtzUQxuTfkL0FUpojYH14fE2w2B4r6RZ 0pwOMAgJx3CGGsucAjJpSZhwSAw21MVIXa05+rRPlUR46zHMxBWFi9QGGyPNjG8CtlGI kTIJqDIvOYyxAmCdK3OarZ+NErrTFJg5WfvAtnwX7PZztQMSgksHrR6REe6pudu4e80V ka3NPw48MSmluzbdyR/2zPzidoA5oTWnQ4u+bj2RGciqB4TOYmTfgme40ATMKeSqd8H5 MgoA== X-Gm-Message-State: AOJu0Yzm8rRhM9+fAD8OqvxXoin7xwGP/7nnfmrg96XOz8PFiFk8dSoV 8pkuZ+4dI1scUpwTjsfgYs8A5vHKhCnatmtguYaD+elCCDPyLXHHP3TNIF9C X-Google-Smtp-Source: AGHT+IHCSW+MgtEmdHVUti9+WxD2hWCD0NmfCyU2sjka1LkmR7bv5TKrJwBuID2fpVaAEzlYPQwGNg== X-Received: by 2002:a17:90a:e50c:b0:2a2:7817:f591 with SMTP id t12-20020a17090ae50c00b002a27817f591mr7838981pjy.48.1713201555986; Mon, 15 Apr 2024 10:19:15 -0700 (PDT) Received: from localhost.localdomain ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id o19-20020a17090aac1300b002a537abb536sm8751648pjq.57.2024.04.15.10.19.14 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 15 Apr 2024 10:19: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 v3 2/4] mm/filemap: clean up hugetlb exclusion code Date: Tue, 16 Apr 2024 01:18:54 +0800 Message-ID: <20240415171857.19244-3-ryncsn@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240415171857.19244-1-ryncsn@gmail.com> References: <20240415171857.19244-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 137A618000D X-Stat-Signature: uggzecepwr99fnngt5qq1zbxknzepnku X-HE-Tag: 1713201557-505332 X-HE-Meta: U2FsdGVkX1+ls+qmBqc5B4F2hDEQmXdg1GEOV38aGx7H1G5KU4GJQ66PpnhbHF+91GMLvtyVA7YXFFwCNjHsCQKphhUxPmDQy3YybOGfRm1+mfOUZYc716t0qcHKH7jitq3ATdpKZ4I79NTLqV3djnHFuudqUHIJxeu0m/H9xdRnCu5zQ78MwomZhojdJSBnNdB7odSV1x0NCU2bUL0v3DKb9D96NvHEiMi4mBCCeWQDaH3Kg/3bDDcAGYzHPJrnd/sETcN+qhiN6yUW9gAmFzdsVAx+1Rw4VBYuYI0qKkAhDkj62yl7bWBG9qpyOlGDA/Nq0nnLc6ULnitRbMJLNiR+jZk0NII8lrQ7nm9aX5VHprMa586qtfCmEBx1Y55NjQ4KCJDvbqyhk7JemAqzUrvOa7/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FlpWxqFw2R4B0QEX5qmsYNT5VcoSfdBnj0XAAHiz8tjL/1woH02IWVnKt6gg1zs3tXRpLa421i6FEpTKRsS8EveGndM9W6nnWDkK4Vs3syHoNwpAuxO6M6A3abYjDHCZg3YniGkk9fKBU9F31xmQcBrKAy9W6aTnYr+F4lu2MPLcPkj9VM6PbWBZifvmBM5sX62MLr++a7VirwAu7Pj1sQX+8stKW/xP3M++ASWnsBiYndEDsL3rdvSwEk/Y9wz3vhQouTfJA== 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: 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 12089c24abfb..17a66ea544e7 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