Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp145635pxb; Wed, 22 Sep 2021 18:25:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8CgIvtGqziAPax/FT1+7PfISQ1OMpjLqoNL7k2ljmO+oX73AJNWvwauyVunfemsyH3/Eb X-Received: by 2002:a17:906:2ec5:: with SMTP id s5mr2255457eji.192.1632360300097; Wed, 22 Sep 2021 18:25:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632360300; cv=none; d=google.com; s=arc-20160816; b=K7TY7YNzxOCsQyqB7CkpVRXn+utEE9MvhBNXXvHG7dNSifrwY8oyIsAoOYn2q/j2Q7 bvFn8fcJOWSV3efb0eQUUQgzxEmcHmYnBUUdPkO/p8deQPDqm85Ixy141QS4Rh76E8B9 puywQzmylr14rmPNd9b3L7QlYtbE1IOh3ibq2iridmfmW3Hn3vtCAG97P12yzQKvXMoZ Sk/5hISywiSxKKFQP7q9qcHT8WRSAz9xv2Lsfi/U/0So5+WX0Q1NO1Kas9PmPYXHgcDT WmjZtoVj9VWz4PT6gMdCUWsSshAHO0cBorUvxk9wlYSpOkPIIMYSYcTdSk/XxpUPJd79 tY5Q== 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=vegAYHHwWq1ucbb5wAql7Fq5zi2BQ/ySb7VWAZVFi2E=; b=h0nTaVVVWSAdiX0maNP+2tg18sPT8ncQNyoSO1HC94kzqk9GjLRR04NoaMm6AGpLsq FtX2QMNnodcgASjB1cBUi3Hc9c4vJYjwTCNC+UrmOS2UybphsX9oTNXsp36GdGYwVj3S vmV3eoJR5BNf9HY02Jot47jeIAGqlSeKIYXeA2LYvjOXPkN0hQAtNHbcOYiNRl3YWknU byO+8bqrmtj5CZ2P7RsskUPYQHN8/2pZ/gLV6rd9VUNhhnVzK+FkVg97JdQNch18oSzO CQFhNiwlMU6twc9ze39WiyXT0UDCjm7Ck+kCUz5FBeFg9pZmGGie3wPVDDlUE/1SVGcT HBsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=TFjcvXxS; 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 w25si4903658ejk.769.2021.09.22.18.24.36; Wed, 22 Sep 2021 18:25:00 -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=20210112 header.b=TFjcvXxS; 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 S238806AbhIWBYU (ORCPT + 99 others); Wed, 22 Sep 2021 21:24:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238177AbhIWBYU (ORCPT ); Wed, 22 Sep 2021 21:24:20 -0400 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98601C061574 for ; Wed, 22 Sep 2021 18:22:49 -0700 (PDT) Received: by mail-qk1-x735.google.com with SMTP id 138so16227558qko.10 for ; Wed, 22 Sep 2021 18:22:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=vegAYHHwWq1ucbb5wAql7Fq5zi2BQ/ySb7VWAZVFi2E=; b=TFjcvXxSWkkR0Nh9wFz2aZ4K4yNk6JJBI+NS97vRGxt/BD1h97F0GYiRDUv/fLZOv9 ciHK2yFJUc/BBGKHwy5+torH60ukEx24FtkrrltDf9kwJJ8qtnqonF7V1Eds5E6swvRc B+4oPl31Heh8O5BENZGK2EJA2MFrUOJvhUoBW7NUGnD5ARaIY3pusJjjeTBiPgoyWlzG TZ+d57lBeUiVBc++9mAo8VuTR+qC/WTtA9cdQYon5nhZ0cks/ZHzu5oeZBG561xy2HXB E9K5yIimQIIl4HhO9/aMRjKFwWJep6tiGiOqaDfMkaO2mmsaf3cXZmnqdD085ityfZ14 Pj0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=vegAYHHwWq1ucbb5wAql7Fq5zi2BQ/ySb7VWAZVFi2E=; b=P0aC+oKKeqs8KfFIYm6O+36IiZ9ITORjKFMOZAHAI2eREsHM15aNpau+ztc65O8c0u ISiiFQAdE4SO8a4xkjiC1sJ1dpCL0nUCaIcNIGmKflcfArdnPC4q8aCFqILE3rSl0U1d +AdIStxy/D9XzG0Yyf0FN5RydROa6Q6EFoQdCpvON8IDFxVzLi03V22IiwwdHwuGPTF2 WVhoy2Ttc4K7mqS775ge/jig3DaIUIwssEX7EXrCyNpLjrt71k+EP7ZJvvFqm6e3oZeN 6iTNwo9hY9cT2YnKOfB4RVaNWkPqYZ4IH3D41YFsEVnUW+n927jWiqY7T1wmuikO+XgO 5rQA== X-Gm-Message-State: AOAM532lnlQd4caZuUuXZoSZ88tzPNw6F/DKCMWzimEbgyTx22QT/GxY u4AwErt+1fxBvW2yCwXCuSTBqg== X-Received: by 2002:a37:6350:: with SMTP id x77mr2463135qkb.356.1632360168544; Wed, 22 Sep 2021 18:22:48 -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 g5sm3021545qkl.48.2021.09.22.18.22.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Sep 2021 18:22:47 -0700 (PDT) Date: Wed, 22 Sep 2021 18:22:45 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Peter Xu cc: Hugh Dickins , Axel Rasmussen , LKML , Linux MM , Andrew Morton , Andrea Arcangeli , Nadav Amit Subject: Re: [PATCH] mm/khugepaged: Detecting uffd-wp vma more efficiently In-Reply-To: Message-ID: <472a3497-ba70-ac6b-5828-bc5c4c93e9ab@google.com> References: <20210922175156.130228-1-peterx@redhat.com> <24224366-293a-879-95db-f69abcb0cb70@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 Wed, 22 Sep 2021, Peter Xu wrote: > On Wed, Sep 22, 2021 at 04:18:09PM -0700, Hugh Dickins wrote: > > On Wed, 22 Sep 2021, Peter Xu wrote: > > > > > > Not installing pmd means uffd-minor can still trap any further faults just like > > > before, afaiu. > > > > > > There's a very trivial detail that the pmd missing case will have a very slight > > > code path change when the next page fault happens: in __handle_mm_fault() we'll > > > first try to go into create_huge_pmd() once, however since shmem didn't provide > > > huge_fault(), we'll go the VM_FAULT_FALLBACK path, and things will go like > > > before when faulting on a small pte. The next UFFDIO_CONTINUE will allocate > > > that missing pmd again, however it'll install a 4K page only. > > > > I think you're mistaken there. > > > > I can't tell you much about ->huge_fault(), something introduced for > > DAX I believe; but shmem has managed pmd mappings without it, since > > before ->huge_fault() was ever added. > > Right, I wanted to express we didn't go into there, hence no way to allocate > pmd there. > > > > > Look for the call to do_set_pmd() in finish_fault(): I think you'll > > find that is the way shmem's huge pmds get in. > > > > Earlier in the thread you suggested "shmem_getpage() only returns > > small pages": but it can very well return PageTransCompound pages, > > head or tail, which arrive at this do_set_pmd(). > > But note that uffd-minor will trap the shmem fault() even if pmd_none: > > page = pagecache_get_page(mapping, index, > FGP_ENTRY | FGP_HEAD | FGP_LOCK, 0); > > if (page && vma && userfaultfd_minor(vma)) { > if (!xa_is_value(page)) { > unlock_page(page); > put_page(page); > } > *fault_type = handle_userfault(vmf, VM_UFFD_MINOR); > return 0; > } > > That's why I think it'll be fine, because it should only be UFFDIO_CONTINUE > that installs the pte (alongside with allocating the pmd). > > Or did I miss something? No, I think I misunderstood you before: thanks for re-explaining. (And Axel's !userfaultfd_minor() check before calling do_fault_around() plays an important part in making sure that it does reach shmem_fault().) Hugh