From mboxrd@z Thu Jan 1 00:00:00 1970 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 D81A3C4332F for ; Wed, 13 Dec 2023 20:42:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 584096B01F1; Wed, 13 Dec 2023 15:42:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 532BA6B01F4; Wed, 13 Dec 2023 15:42:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3AC836B01F5; Wed, 13 Dec 2023 15:42:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 28A386B01F1 for ; Wed, 13 Dec 2023 15:42:13 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id F3F50140326 for ; Wed, 13 Dec 2023 20:42:12 +0000 (UTC) X-FDA: 81562967346.09.2C58D7B Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf23.hostedemail.com (Postfix) with ESMTP id 359F014001E for ; Wed, 13 Dec 2023 20:42:10 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="tQ3Apn/5"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf23.hostedemail.com: domain of shakeelb@google.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=shakeelb@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702500131; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=uc9oGz4PPngc6hvAUNgglWjHUohHzdG22g5pc1epW4k=; b=4rNEYoy/SZ45eOGfE9ZomJBmmRePAzZpoiBPDzAE8xvucZdrn/yC7ljXmISCMQu64SXHZh UX38OgAd7qI7CF/8qeDqZ2XHwmwYx8ohEU9Eie2vCrvyomeiRR4yE/+5M29eWw82TGhNHO DSeB3Q2LvfYLWtck6RgxnwDzny+GNr4= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="tQ3Apn/5"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf23.hostedemail.com: domain of shakeelb@google.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=shakeelb@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702500131; a=rsa-sha256; cv=none; b=3V3EZa9UJ8+lJE+Dhk66VMdCUXU5m5Hxq6bnmPB1euC9sm4g05615hv3oBpd4IroV51+VU 7R0YIrWWtJW6Lzv6o/7TLAaJg+Sl1bVpnv1MBR4In9nJNBuuC794O/IYQlksHccMw8xkIQ gJfnT337jjBUS5s5kCNc8K64uYlFPvQ= Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1d0b40bb704so34325ad.0 for ; Wed, 13 Dec 2023 12:42:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702500129; x=1703104929; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=uc9oGz4PPngc6hvAUNgglWjHUohHzdG22g5pc1epW4k=; b=tQ3Apn/54jNFgJUTRDTokqWTqS9rFCWb6RIR4uq+DS/xkEA3U3tkS6gkVlopc1NJZc gVxw4/EauXA3IrDiYavA21Mfdagj5z4NnDuz1jI+NtKFO3UN4JmAnni+jbPB/bbiC260 0AW0J4kF2CtUQmK/X2qFJLuuFHXgiQpAK6+HXUqcGX71/OznuWSsPVF/WSKYWmkN8ExM bW/553iJZ4UcG9a57xSJvexbZypQE5EwIN6DdInPyJCFbzqLWVjOOIP3a7iMBgqfir0h +gyR5FdxIU8qF9uEBfF/mOV4XbKjMR2XJygRSH0tFxpYKS2NLtR0N5YnFCwIi4dLzPdT Z+Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702500129; x=1703104929; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uc9oGz4PPngc6hvAUNgglWjHUohHzdG22g5pc1epW4k=; b=Rdw9k5f9rZ3JRvuZrV5ncIrDb9UEF29i2rLzlF69WSueCrCAnm82rzfg5T/k4hH8c7 lAaWzevMERkmqqRTt95x4acKS8k8PzTNdmSXz9JJYit9WaKOzn7bBDs2ztK6pwK94ZmM eQ0H1Sdb/FYcpGUNgu9kjegSfayOSZHnBOBqRS17Zb+vQiR3KFQSJDYDmP+JLYCoTUfE YBUfSpM/XtoHhkTyRWFc1c3Iv4LRwKXGRqWyqEEejy2n/VvUQj2jrs5AUCCpaZvjEo1d vu3yaAv9Vs6+yf67E4M0WIGYIV5HwgomfmU2uiPGSyEJBwVHwjITnFIzpLU2KHMJ0a3R PD/Q== X-Gm-Message-State: AOJu0YynvHzgh2bmb71TpXkpLF1zQAGfIZmC5O7erYlSvQl+gRaxVNfu Up8wcpqcl9eSz2rmNEj75Yz6/pFt1QZdgDjbeYwZBA== X-Google-Smtp-Source: AGHT+IHQ54ciaQGCcxy69sZ2YanjchNAwTBoM18gxTFg282eqf3eggBQDf06UgHTKmLuEqahWSIJITA82qoIIrjNUKU= X-Received: by 2002:a17:902:c407:b0:1cf:dbef:79c9 with SMTP id k7-20020a170902c40700b001cfdbef79c9mr1296915plk.2.1702500128776; Wed, 13 Dec 2023 12:42:08 -0800 (PST) MIME-Version: 1.0 References: <20231213130414.353244-1-yosryahmed@google.com> <20231213202325.2cq3hwpycsvxcote@google.com> In-Reply-To: From: Shakeel Butt Date: Wed, 13 Dec 2023 12:41:57 -0800 Message-ID: Subject: Re: [PATCH] mm: memcg: remove direct use of __memcg_kmem_uncharge_page To: Matthew Wilcox Cc: Yosry Ahmed , Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , cgroups@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 359F014001E X-Stat-Signature: 84c8dkbgsnewiihed75j86fafywihwsg X-HE-Tag: 1702500130-937793 X-HE-Meta: U2FsdGVkX1920Gjl2WK25TV/sLgOAySyHR7Ku5X16zk7qY+aOMnS8Zfia7mxg4/um69XxwP01TycNO7w6oHidz9FPSeEbtjf2f2nGL3iL3KVxMuIN0qN3ligdRmQoetyhKhY19on1cR44mL/0YMVIpMo6Ml9in0JrXY1xSVVWg1wQgdt6AoYUU9tLDBsHyb2UKyulC0JNgjL8FhHlfBk4oi+v2dcoctEDAyEYZ61n9AAcEEO5gw7rOhv2na1PpeUchgsEdc6OyqLwfFWFWLv1cXlcUxK+bUS3Sh/D0Aj/lacaGbcQq982No7gDrKuD7cLvTsLloAi3LNjGcym/C7zRv1IApQovIDBK4PqT1uI1R+YQprhhqdjpQMM2vGNbZTp2Z2D2BM63sPCOmpiYwDQIbyG4D39Q0y4zzIXBzmhto2cwyLAnTzERYEmsxCEFOIEm9nw2oqLrPh0Y8oHEL0ceMciGoFBwEttZkxD/oJ3quCOKvf7uOwZ1HEw0BjyWNHp8pvqFtI84WsCtQC3U9xBMlDJGEUTJC71Qi2bpxJRLSXIeWIcHnukbSPFO9UKibLVA8f9NXfnqhKuFgU3Jtfvm4EV9Mp6C9RwUCjFK0NRwol+Wmpv5BouXmlpEYPbhupZ9+CPKqnfxT4Gf4pfYFoNLsRfzND0OREvJsX9eAG6ildIzuUBjWhC0pCek7gPJq31s1ZVbDG9UsuEn3SRSepsenajyP+hm7nFZajDvpK7RcEYbjgJhujJS20q5aaD3ZNfr8ScPda44VfXu8MXl5ZT7BGEe55eJSQ6jRciDoCyH93zaTBtZ7KFSzyhaNjnAxXjd4OQB1xmx6NwI/+Vr6S3DFXfgPeSXnFInTYcPOiranj/p8tgam6woM1jkLl4g82be37+g71xWbtMzJHe2KURBHK0rZh/sHnwZ6xayh2luTpHb/wwFxiWMa5/Jp72aTJKezkEhxx3f1jgq3b77G KdPZlFU3 y6ZiqccxdNO6JBboqodgLS+5ZYoSYzxDo6FvMzMTngLAQL0AKg9uQX+wFUsF5cS9WyLqHgGSsJkJh2ZKW2pRYQACbD2YrMbzYFnnEx/NM05XxEKfTIUVFtSN8pR9y0SKvVE2LOnbbcrdvZQkpUuZGaEbohZgW65ZmhA/hopHLY2fpvNbcQlfn61WS4opNk697oy1EKTxAS3qT8rn/De2uc4hdVUNfQIZbCUdwXWcAaZB4Xbu53EXtJLFa+o3Kv/TybnZx5F0KvkrDqRgJmdVV4gxB6zEss6PIgPze1ZCOC6t3r/lPqGl9kxeSImuJxa2DnSxfWOIso++r+Fs= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000051, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Dec 13, 2023 at 12:27=E2=80=AFPM Matthew Wilcox wrote: > > On Wed, Dec 13, 2023 at 08:23:25PM +0000, Shakeel Butt wrote: > > On Wed, Dec 13, 2023 at 08:31:00AM -0800, Yosry Ahmed wrote: > > > On Wed, Dec 13, 2023 at 8:27=E2=80=AFAM Matthew Wilcox wrote: > > > > > > > > On Wed, Dec 13, 2023 at 08:24:04AM -0800, Yosry Ahmed wrote: > > > > > I doubt an extra compound_head() will matter in that path, but if= you > > > > > feel strongly about it that's okay. It's a nice cleanup that's al= l. > > > > > > > > i don't even understand why you think it's a nice cleanup. > > > > > > free_pages_prepare() is directly calling __memcg_kmem_uncharge_page() > > > instead of memcg_kmem_uncharge_page(), and open-coding checks that > > > already exist in both of them to avoid the unnecessary function call > > > if possible. I think this should be the job of > > > memcg_kmem_uncharge_page(), but it's currently missing the > > > PageMemcgKmem() check (which is in __memcg_kmem_uncharge_page()). > > > > > > So I think moving that check to the wrapper allows > > > free_pages_prepare() to call memcg_kmem_uncharge_page() and without > > > worrying about those memcg-specific checks. > > > > There is a (performance) reason these open coded check are present in > > page_alloc.c and that is very clear for __memcg_kmem_charge_page() but > > not so much for __memcg_kmem_uncharge_page(). So, for uncharge path, > > this seems ok. Now to resolve Willy's concern for the fork() path, I > > think we can open code the checks there. > > > > Willy, any concern with that approach? > > The justification for this change is insufficient. Or really any change > in this area. It's fine the way it is. "The check is done twice" is > really weak, when the check is so cheap (much cheaper than calling > compound_head!) I think that is what Yosry is trying i.e. reducing two calls to page_folio() to one in the page free path.