Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2848320lqp; Mon, 25 Mar 2024 10:55:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVpRhD01KpFtf1bnTd5Qqfl3tlrW2hw+qNL3CdkKwZpHrATVcTpie4hhFrddA94aFKApuY+Z1XCFoJoPWDvjg+6aEtIIoSuGJlbEff1rQ== X-Google-Smtp-Source: AGHT+IF2/gqfee2nnwak/XcLt6h6PFdsmSlViL5ksQwZ+MVjgGXu2TdPyL6DR1x5xCpIFTOKyxu4 X-Received: by 2002:a50:ccd0:0:b0:567:2a22:6e86 with SMTP id b16-20020a50ccd0000000b005672a226e86mr5900776edj.22.1711389340377; Mon, 25 Mar 2024 10:55:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711389340; cv=pass; d=google.com; s=arc-20160816; b=hOiiGC9b6fo+29+8SHuROhz9szXvanso/yOp3N5/lakK1lP95uaRg41gvV2HN2eiPl PZbxrRTeHLdKchN8vKp9GGIPgRSOrCH2gzh0BYcnbJn2vkiRICuKSHKmalAPwKGboRuo upWjFs9dqLra/h1KWP4CG6W/k0kbYcHOBNYI2ApRMttlgyZAqDXlovdUXppxlMUbB/Kj ERzGcTKHxIJM+tc0PIFbLdL8RsUiyKd1mL0A0nFoQbWo28X3Wr++Q0QeuCV900jm142a ehK54X0MwhytbY0dIWgA0hqJZXS2XE57RaYBABGYall33S0A7bFf/5OxW2Pk4CdG4Wa/ /OQg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:reply-to:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=bN9a48YnOEXH7sPm0Ke4Oa5WKVmRd1RkDjnQJHDaF+o=; fh=5PFKa62XUJ6cF44q2XZZEA7vgokTZuMgBFcecUwQQgw=; b=alxHKpLSdqa4PLJAwgT+7V1mvMWWBpZX6NNKoFR2/q7tGj+5Di3p3pgz9CEm6Gow4b gl9Yx93JEGKxEwLN9FpzMUvhs4J4b4z98RP/8a5iW+L4Wz9oh93xtoSbY3o2wC9o11Yt 795ArE+V52yBLydZ1o1jrEQCSfkElip+HhYJtrreNkYY5NN6sv0/CuV5aGexmEAXSFFq 3mTueMLdjBjSzsNb0htCsjhebT50HzjcE7xVOC8uCR/OV17199Ascmi2FFoq6cawOpg+ NtU4ujdKcFO0PvCU9PV4JsVVPM2Ua5ntbQrrl5XjyE8dKgEXryHpWxcE1Gw+ON8C5cZJ HMnw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=VBCS0I9R; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-117558-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117558-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id b61-20020a509f43000000b0056739aba263si2683199edf.440.2024.03.25.10.55.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 10:55:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-117558-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=VBCS0I9R; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-117558-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117558-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 1CAB31FA3A2E for ; Mon, 25 Mar 2024 17:55:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ABD4213D88F; Mon, 25 Mar 2024 17:14:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VBCS0I9R" Received: from mail-il1-f172.google.com (mail-il1-f172.google.com [209.85.166.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6380113D605 for ; Mon, 25 Mar 2024 17:14:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711386857; cv=none; b=HqhJNQDxJzNI5hVHoDuHkS1sor1oKS6qD+S36djQjBKAjh8F1a0qmIz+BYYHrLpwrSgKCQ9fe9iCYGUDNgLKZaYoD0XRjiVtMFI5bkgdRezVd4P+uOaR37d1vNpzMwMtWrDoEs1ArFcss0Ce2eDfxvWuq/kuUDABMU2tKhHcgjM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711386857; c=relaxed/simple; bh=LWlwlamGO0rfQ1EM8aLmO1k7D9FshXdChnWs/pBPSrU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OUgiJLmpOaSgX9lnXpU5OdMFQ9c6kIa01unmjDuFnforvWTtjWK15HB8f9guI0a5SirDW9at8bktMyFNvB89MAg5iG3cE8ZSLDy4xeh2uwv586bmdeXxnXOXAmL5nfFg31U51UgdS9yrYgDaJtXJiKnXa4rc26TTe82mZJaNAtM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VBCS0I9R; arc=none smtp.client-ip=209.85.166.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-il1-f172.google.com with SMTP id e9e14a558f8ab-3688d20b28dso5512445ab.2 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=vger.kernel.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=VBCS0I9RaAf56C8UqRa/PYanL+cxS52kVuGhIBQSlEb7aZh3l/xQoBJMsyhgcA7rwl h7rGkp2+L4x2/Wbt1FoRe3gtqJ7IC6Tm5CKko10CpCZzElnRGPC70tCQ3gAqh2JwvpR8 f1MwPzlC9/C44ffV7JHkvl24pd20V5vfMcf5Auk+zlEbKwCRfzoQWmaf/5TJwassnEu3 yihejF6TfMKUMsHEQil4u7u9HdFhkb5hlcVoocRcDkbkWeDRFRI+3ysjUEcCHjubWKDQ a9hFBkTwWm4WI/aypQLgiQbHpdUWPLq76yFPWPRpa2oBeNHxwhEDuGaL6j+oiIcg/Ozr SeeA== 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=X1UP9SDeMZIHyA1pZW6HO5IDEFbZuMkO20W7jp2A3AxwEEewLQZArD1FWjXhPkqbNb 5cNb1GOBkRcTzqREbHbtHrQOazq8qvkozibSfdYUaZ5ESRGHpZ5+jJ4pXqv1olNWK4JI i5Qc5DHwDnGTwEjqfKZxprQIbocm/0eCHIps72iEidzW1E/6bSVadSMwbjIrn8eIGz5i JHAH7rWiNSslrv1PMNnIgvjZ+iMc/cYJsKkKj8hhnB0aGEmahnUacqONyZ3ZeGBjUIZq w07TSVl0NPkLEtGiDLx3yxuku7tR3yTYvdNoF6BxQQLNappiHp9WOrTeGXLzvZtkhw9O L17g== X-Forwarded-Encrypted: i=1; AJvYcCUUrZVUV36eWN+SeJtXWy3mPQLd9uuCM9RDsjctdU7A5+TKgPjK5osC8zhRU7txKp0scZ4KFfX8vIhmMqUGpJOq8Lrd8R0jfvGKTmOD X-Gm-Message-State: AOJu0Yx2Y20Q/Isne93dxqQ4Fk5CTX9l+utzD3Rr+7o18cbQ+CvUoJRQ j9COdhink0gqQT1Kxs4xrlrZySl6LeruIsJjMrBqJw3fBAgmHdEZ 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 -- 2.43.0