Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp690988pxy; Sat, 31 Jul 2021 22:41:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/eNcc7rLWIpXMPw/ourLwT67Z0jzNwTOG6ZPsdS00AS/ra9VJ6KS5i0PSEc4Bqhal1S9s X-Received: by 2002:a17:907:2674:: with SMTP id ci20mr10239913ejc.84.1627796509439; Sat, 31 Jul 2021 22:41:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627796509; cv=none; d=google.com; s=arc-20160816; b=bf5a5fpZiR3/NBqWK3xiVnsXMbxdrHmiyiF54PYnlhGnOESZ3X4n9KYlgHBl21wggm r416PD9Xihd3LPFuAxM7dLneXGVyhmGpIUdyzuWUpTTvXk7zCeUXqNomzntc8iJwSHFz w//vPuzCfw5v726pdbUe/z5nEatCrATELgBst51JpUfT8cfEVN/htG2kCRoQplss8caO T1mXQ+cC4p2UfmwtQepKVRHhx4LrNb58UUxOCrwIFllYxrNowEYb1Cl3qe7NxYXhbtoR iJ1HpEsTDzBs90En+9JSxqnXjADPbP9oY7kOkRjDONANKBHQCWKPf/M+UoKK90WxCW4Z r4ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=iGWJvQyFhYWArKOyYVxVLAiTfV4uzV67U+jmo+FAouk=; b=BdJYmS+8LCCnKt75KE30hkc2+TKiFgkLCdBez2Gn5lxFLAVZnKYk8eRHo7kUni+UO1 VKkj4yn//eyoFdSyvrGwIu5zRroDQsPoaH+KmRIc/j4wZ+Wfnjse7rdC1X7ATHW/1N2W 7e2ORvIvK6RJ4L/8g6wHV+vSZst7gH8M+rN/pST/8eQrumlmUnn6OdIq20j8Kxzn2swF MKC0L+KX8iAAAYzyXcJ/3klez0dkG6UcuwD8E60dmMymWYHqzfZQn1pJO4P7A/2LkzdN KUOuGW5ATMbpqL+GfiXkf2zJBwFaD20OqdEaR3dF8AzKGKAVAw9/ke1PjGsjIxTltNPa Exew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=EMVItB+G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pj24si1867315ejb.143.2021.07.31.22.41.25; Sat, 31 Jul 2021 22:41:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=EMVItB+G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230240AbhHAFiT (ORCPT + 99 others); Sun, 1 Aug 2021 01:38:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229491AbhHAFiS (ORCPT ); Sun, 1 Aug 2021 01:38:18 -0400 Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8D9DC06175F for ; Sat, 31 Jul 2021 22:38:09 -0700 (PDT) Received: by mail-qv1-xf29.google.com with SMTP id d17so7368264qvn.13 for ; Sat, 31 Jul 2021 22:38:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=iGWJvQyFhYWArKOyYVxVLAiTfV4uzV67U+jmo+FAouk=; b=EMVItB+G7FfUUoNMnfQwOUjV3ArbnBTu1oFkd7HLTYn2tVC6AJEYtE4T+IsCywUSpg Gw4RUEMFPxQ3c9322Xw+RyDT87+g5/V4dM1xr6NBy3DpWF3Y02qrA72ey7xkFYZJd8of qvOv35ebfTG1e41XeO2QIcJBLmf4x0wzo4lWLjyI/uSpUUbEIQw1c6tXOakZLKmIU5vJ UR8u6931Pg3iNzH27zPBbSiikVRqrIuOAPnoELhiKdGJ5DZrHSq5Xgrf+zD2wDgtJvSs z16Y7Ke/ASDEDjgWOS8tZrDCCMqsa1ToXM08aiKAmUQOQkjWTt8QElX2iHgbpwCxCk0j zQkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=iGWJvQyFhYWArKOyYVxVLAiTfV4uzV67U+jmo+FAouk=; b=VcQFvekTWN6ScAsf0rmkRS+2vL8J4PhTRUEAHPDvULW6r9ujmT5ruwrWVRkijke4Mr QHmaByyrF9tSkwKiZPxkssdLzRUX7r36fLMBH2m7vQVreF4j6tvNbvJcAE21HTGFbvvl BdIHMeyTQgcuQ9yRX+SMJM6wAHKivpW5caFk5tSc/4aqZJpvfvuxXE40HmVLbDtzT+en WcCRkCzwJaMVWAl09R67fiwbom774D/F8yHdUBDcAMn+JVglNL8YuPUHSi+p4giUiydz YO/QEbV1YyOOY2wnX86TSoHytpEs3DvMlqFbQq6mpH1DNAtU9HyNCrJaNqjJINaTtwbP tmMQ== X-Gm-Message-State: AOAM532VndmwY7AE+tP84WBQJUfccLIB4jfHvIs+M0houBpz9yo+dpwa PBfmddZePf2jYFlgAvo/inaBtA== X-Received: by 2002:ad4:442e:: with SMTP id e14mr10587697qvt.43.1627796288923; Sat, 31 Jul 2021 22:38:08 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id h10sm3613305qka.83.2021.07.31.22.38.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 Jul 2021 22:38:08 -0700 (PDT) Date: Sat, 31 Jul 2021 22:37:55 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Yang Shi cc: Hugh Dickins , Andrew Morton , Shakeel Butt , "Kirill A. Shutemov" , Miaohe Lin , Mike Kravetz , Michal Hocko , Rik van Riel , Christoph Hellwig , Matthew Wilcox , "Eric W. Biederman" , Alexey Gladkov , Chris Wilson , Matthew Auld , Linux FS-devel Mailing List , Linux Kernel Mailing List , linux-api@vger.kernel.org, Linux MM Subject: Re: [PATCH 06/16] huge tmpfs: shmem_is_huge(vma, inode, index) In-Reply-To: Message-ID: References: <2862852d-badd-7486-3a8e-c5ea9666d6fb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 31 Jul 2021, Hugh Dickins wrote: > On Fri, 30 Jul 2021, Yang Shi wrote: > > On Fri, Jul 30, 2021 at 12:42 AM Hugh Dickins wrote: > > > > > > Extend shmem_huge_enabled(vma) to shmem_is_huge(vma, inode, index), so > > > that a consistent set of checks can be applied, even when the inode is > > > accessed through read/write syscalls (with NULL vma) instead of mmaps > > > (the index argument is seldom of interest, but required by mount option > > > "huge=within_size"). Clean up and rearrange the checks a little. > > > > > > This then replaces the checks which shmem_fault() and shmem_getpage_gfp() > > > were making, and eliminates the SGP_HUGE and SGP_NOHUGE modes: while it's > > > still true that khugepaged's collapse_file() at that point wants a small > > > page, the race that might allocate it a huge page is too unlikely to be > > > worth optimizing against (we are there *because* there was at least one > > > small page in the way), and handled by a later PageTransCompound check. > > > > Yes, it seems too unlikely. But if it happens the PageTransCompound > > check may be not good enough since the page allocated by > > shmem_getpage() may be charged to wrong memcg (root memcg). And it > > won't be replaced by a newly allocated huge page so the wrong charge > > can't be undone. > > Good point on the memcg charge: I hadn't thought of that. Of course > it's not specific to SGP_CACHE versus SGP_NOHUGE (this patch), but I > admit that a huge mischarge is hugely worse than a small mischarge. Stupid me (and maybe I haven't given this enough consideration yet): but, much better than SGP_NOHUGE, much better than SGP_CACHE, would be SGP_READ there, wouldn't it? Needs to beware of the NULL too, of course. Hugh