Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp8266534rwp; Wed, 19 Jul 2023 07:33:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlHw/Yx2caItSC5Lk27c1ozZ4br21mnvqtwU6QW0L04lUKc7N150b1/TwKbY/OhZ14iAs+ku X-Received: by 2002:a17:906:7714:b0:993:f497:adc2 with SMTP id q20-20020a170906771400b00993f497adc2mr2258426ejm.18.1689777236579; Wed, 19 Jul 2023 07:33:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689777236; cv=none; d=google.com; s=arc-20160816; b=L3o9zJShFYhR50PxGfjOQb6dcbI+Ly8HwVGLk1aETj1xNUyCUvjJRcd3apilk0V+0x YSjcHmmwQNx4pEgO3za+yaPe9kkwmwPuHHtcQIrMXKp8ketDrupnw+Wg7BkhTrScXQuC lpiWBFuD2HAJEIEqFIBBErjMu4p9+NqQykc6q6PjGKSPr7WPS8yA2XK7CTqp2X58qZ6U yOY3HyxNPU/KsP9TNyJrjC2gtesvETdR3Nmcrc5dgsLCzb8qMuWcY0lcEK22U0gHkj2W GTXh5p/sjbZ0EcAbRRmNg0uuIWUGL8O9dPlTNgSI4mw2iwwUkr6kSSXt7yyuWqFTgSuw Qb/A== 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=2VK55DG3Fs7PTghAKQd0jM8nvqZIPZ4glcR3HhFBT7c=; fh=L/QDuL9mk8mLv/6o0NO1j9O2YuwIXZHJrdGoJXPbRsk=; b=b9N+Se2bHm91BtDdsUE0kHrH+1oRFD2+d72qa0uSVhEpKKoGjwCKz9VVjWv8kr8Yip FOY4+Pb7UdWjFy5Z8ssh6FwlISjx5mQOG69IZU6F1NuQsQsWk8oHBCYphhb2Pe5Kbjap Hqez5W4DrCQkPX0PpPn8obXU2ucoba+Pt32hpv0nVORuDbSZSIowFlQCJmLuwbCGqHXG Z9KXzA/LW4SlS7ZwvZkRzlLnh+qHO4yQ/YvS2Ul/6gGllnBQQbokjmKVleLQKgDmCmFk SkpSHjR/8Lh4SvROXt2/0FWJw0r0jh8Apf3TyQdjr0zBh6uHtEnQwDlIX7MJtIx/Z7IE doyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=7jfU311s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ka13-20020a170907990d00b0098896420108si2992752ejc.170.2023.07.19.07.33.32; Wed, 19 Jul 2023 07:33:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=7jfU311s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231680AbjGSO0c (ORCPT + 99 others); Wed, 19 Jul 2023 10:26:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231620AbjGSO0W (ORCPT ); Wed, 19 Jul 2023 10:26:22 -0400 Received: from mail-yb1-xb36.google.com (mail-yb1-xb36.google.com [IPv6:2607:f8b0:4864:20::b36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42DDC10F5 for ; Wed, 19 Jul 2023 07:26:20 -0700 (PDT) Received: by mail-yb1-xb36.google.com with SMTP id 3f1490d57ef6-c2cf4e61bc6so7247704276.3 for ; Wed, 19 Jul 2023 07:26:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689776779; x=1692368779; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=2VK55DG3Fs7PTghAKQd0jM8nvqZIPZ4glcR3HhFBT7c=; b=7jfU311slUUW0UFqd1xP+4htLveZmM27w7SWA5P0Ofot830W2PGNGcLy4HrhdEoxQm az+ILN50Jzlo4maRmOZlUhdjCrGtxh073DOAMOQlyZCSdcDvxCsrVoHtWECGQCV6CMYP dtkRMmL1WsTSmqNv2tW3j4A1S23poCaDbO2S1YBY1oW1aMQtTEPf6UsRY+WbA+OtKrIC Ua7LPGLJzdckrb/5yRJ7bC/gRfLRRWFwi+VUOyu29ro5uT5rEQHlXpAaCoqRhr+mHIqE pK8dmPZI3dsvbXSSHF64DsP7G2TTHotWz5S+oM6rCmanQUB6ET0h94ELWpdpUDirIPGy yX7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689776779; x=1692368779; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2VK55DG3Fs7PTghAKQd0jM8nvqZIPZ4glcR3HhFBT7c=; b=UVZpgABYpkklUc6x/21HUJhBzQa4vnwhNz0Q0xjyTz5hu2xpSFh11bWWQHXjXwyLpE S8N3/7NKBnFD0JNMq93dosrPvk+rVEEoQkYj5LB7ZJKsWTvUqdkCqdcCf5RooH5pbaWI TFTHJTXlL6HIK7NkUztx+mvu6xv2Eab7cm5kcqoxSSHgYWJaJiZywwBUQ3KS9yrHjKuO Gkrtvg451vd7LFcPq3umPWKD4yw8NWkKw4yQS+ismp6KXXcLhqnv9GwHZLi7gB5fum+A 1KsOf/jzl5ZzQqwesK4+ngfiVEPHGB9ET9QXGcZh2juCP7ze0RMB6DgPUlkVBMbYSRQp hh2Q== X-Gm-Message-State: ABy/qLaipCoeh1N4Q+UOxxk2dFGUwnhZdW2A66kxjW+eAaS6Ks+6HBtO Nx5aLzioao0K/CyfTJ4q/YvCfGUaV5b8IVCrG8qooA== X-Received: by 2002:a25:5342:0:b0:c85:d8b7:1b96 with SMTP id h63-20020a255342000000b00c85d8b71b96mr2356398ybb.52.1689776778840; Wed, 19 Jul 2023 07:26:18 -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 133-20020a250b8b000000b00cecd504e708sm651446ybl.35.2023.07.19.07.26.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 07:26:18 -0700 (PDT) Date: Wed, 19 Jul 2023 07:26:08 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Yin Fengwei cc: Yosry Ahmed , Yu Zhao , linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, willy@infradead.org, david@redhat.com, ryan.roberts@arm.com, shy828301@gmail.com, Hugh Dickins Subject: Re: [RFC PATCH v2 3/3] mm: mlock: update mlock_pte_range to handle large folio In-Reply-To: Message-ID: <79f6822-f2f8-aba4-b517-b661d07e2d@google.com> References: <20230712060144.3006358-1-fengwei.yin@intel.com> <20230712060144.3006358-4-fengwei.yin@intel.com> <40cbc39e-5179-c2f4-3cea-0a98395aaff1@intel.com> <16844254-7248-f557-b1eb-b8b102c877a2@intel.com> <208aff10-8a32-6ab8-f03a-7f3c9d3ca0f7@intel.com> <438d6f6d-2571-69d9-844e-9af9e6b4f820@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 19 Jul 2023, Yin Fengwei wrote: > >>>>>>>>> Could this also happen against normal 4K page? I mean when user try to munlock > >>>>>>>>> a normal 4K page and this 4K page is isolated. So it become unevictable page? > >>>>>>>> Looks like it can be possible. If cpu 1 is in __munlock_folio() and > >>>>>>>> cpu 2 is isolating the folio for any purpose: > >>>>>>>> > >>>>>>>> cpu1 cpu2 > >>>>>>>> isolate folio > >>>>>>>> folio_test_clear_lru() // 0 > >>>>>>>> putback folio // add to unevictable list > >>>>>>>> folio_test_clear_mlocked() > >>>>> folio_set_lru() > Let's wait the response from Huge and Yu. :). I haven't been able to give it enough thought, but I suspect you are right: that the current __munlock_folio() is deficient when folio_test_clear_lru() fails. (Though it has not been reported as a problem in practice: perhaps because so few places try to isolate from the unevictable "list".) I forget what my order of development was, but it's likely that I first wrote the version for our own internal kernel - which used our original lruvec locking, which did not depend on getting PG_lru first (having got lru_lock, it checked memcg, then tried again if that had changed). I was uneasy with the PG_lru aspect of upstream lru_lock implementation, but it turned out to work okay - elsewhere; but it looks as if I missed its implication when adapting __munlock_page() for upstream. If I were trying to fix this __munlock_folio() race myself (sorry, I'm not), I would first look at that aspect: instead of folio_test_clear_lru() behaving always like a trylock, could "folio_wait_clear_lru()" or whatever spin waiting for PG_lru here? Hugh