Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp6218526pxb; Mon, 14 Feb 2022 19:09:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJysI4AAbh5QacX1gtRlTLay0UywZODbN+wgewQGmEl1/Zs0M75vjBIsFmRXd7SONsA5/4x/ X-Received: by 2002:a17:906:c40a:: with SMTP id u10mr1314616ejz.717.1644894548631; Mon, 14 Feb 2022 19:09:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644894548; cv=none; d=google.com; s=arc-20160816; b=M5rU9gaB4L8wsHnbQFsur6xhLp/dDdJxX8yhpt0IrkBh1Sp/2X9/5AJbxvUSgJpmao tBAOfRXFqOmsmqn8Q/1mmkT5TmECAhmo9/HcrpO3bAzITj8V3cnfXAs8SqL6Wh6bfjIn 0YJBDe/YoGG+oJVE74Slr4ZIO8SbbQ29nHbWCHfyAQz51/lcNCL+CZHMnohaNJ16K+L1 CEZXM92/TvGav0qyuNPvHzVkX443prnN0o+O5kWQ/DWaZjAWMQMJnbysRD92kam9WX+z yIMzoLbuOTMbr4x9WzYK5sIJaeL8kj7yCc+uNpk754O8IIudzGDaF+zMJ/vVqU9D6kmt wSPg== 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=7RY/qhKlJPQeH1IwAyGGlnES1Mny5ocT5QtyB/fayZE=; b=vqls2hHfofnDD3Q2vZaoH3HOlY7G71/Y/UPMbHOp7QucaBrQ+OCy+zJwt4WcCOB+uW b1+EiQBcR7pRAAoNXJhgpnAjXwhraKF/oRDW9wTB3SUK/wnFxSK7lkqYKK81FkEKK6lq bZP+A96jvhOeLyBZ330qbuobQjkFfTu/mIfz6QrhVVKnrv7tNr2zE/yv1e+vsHvk7JGm uSJV4s6VMdr8nYK1cZ+nLkNca5WLgFSR63dIrbHNIyg3DMKoy6FF6apRv/7vgpnG0uG/ 2sHe38YTiMaHC+p/ynqcYJpu5HR4wBRsfU33/5EI/QrHuAsZHGyB2O7VHsuCCqofkK9N H/PA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=CssZuZOe; 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 hr34si16562788ejc.191.2022.02.14.19.08.45; Mon, 14 Feb 2022 19:09:08 -0800 (PST) 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=20210112 header.b=CssZuZOe; 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 S233677AbiBOCjD (ORCPT + 99 others); Mon, 14 Feb 2022 21:39:03 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:33890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230039AbiBOCjB (ORCPT ); Mon, 14 Feb 2022 21:39:01 -0500 Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D264F1029DA for ; Mon, 14 Feb 2022 18:38:51 -0800 (PST) Received: by mail-qt1-x82a.google.com with SMTP id p14so17348303qtx.0 for ; Mon, 14 Feb 2022 18:38:51 -0800 (PST) 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=7RY/qhKlJPQeH1IwAyGGlnES1Mny5ocT5QtyB/fayZE=; b=CssZuZOe3DBbjf8JJaBjw58IQNx1PjFb/exoxSarxXEXb0Oku+9ZRuCUj5Z7Ybceav LxQzjdOLq1kQgG8GGiKW3Qcn+MN7WOn76nP1logW5v3dLX60adeSoNzxXJZkNF2yUrwx XIP/VjCPuz4BreDgp6azxwICU4A7RuibWm8BmOIru5OKZPerzNFnTXIE3RgfavBFXe4E L7GwFOHtBTXGz0268x1zY/1+ABnLkf1a3F32q/cqc8MXzk5h1SULSzWDWIgkwDyxJKDQ RsslYR7OvL/db5PKlOCiW1UED3kwElfK3o6xq0CcIoCuGhhXPzPh8MgCllnZA31k3/Uj c6MQ== 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=7RY/qhKlJPQeH1IwAyGGlnES1Mny5ocT5QtyB/fayZE=; b=SLEUTEuIys90hbY2WgzB4MBfYNSjjDRKwND3UAvkUo+9M8nFCp1tdVHJtwLhqiP4B8 rBqR9PP2oTXGrEnrUoZ8RnHmZRw45yqxT9eqyZD/m2rTaZaejS4bfzNxUPkqDT1Q5kiR xZUcxC12ZtKhcz8vTPSnsPmWe1o0x/RhSJj3dJmeDf1i8TlyR14HJifZ4x+AQi/tCwPe mff8CqPY4fZtJ+Bx7tNacqjEgHxyTk79DEqpGgEsj7gP07mdIaDIUfEVhdOm4JHBtY8s K1shD3NVAYfSsVXLVw7dp24e7JZqmnIsZPMYHvHGYvlAW0g4bj4nP3y9gHJZ1JFGFlBh oHtQ== X-Gm-Message-State: AOAM533goBSs2qx05pnKVZBzgAvjA472QJUAsFLyirsaNTTtSlW4PnKr TBpyaphLgT5Xvo5u1WW3dUnqFA== X-Received: by 2002:a05:622a:1ce:: with SMTP id t14mr1338296qtw.25.1644892730863; Mon, 14 Feb 2022 18:38:50 -0800 (PST) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id r13sm10993253qkp.129.2022.02.14.18.38.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 18:38:50 -0800 (PST) Date: Mon, 14 Feb 2022 18:38:47 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: Michal Hocko , Vlastimil Babka , "Kirill A. Shutemov" , Matthew Wilcox , David Hildenbrand , Alistair Popple , Johannes Weiner , Rik van Riel , Suren Baghdasaryan , Yu Zhao , Greg Thelen , Shakeel Butt , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 11/13] mm/munlock: page migration needs mlock pagevec drained In-Reply-To: <55a49083-37f9-3766-1de9-9feea7428ac@google.com> Message-ID: <9e2ed861-951a-6e86-e298-a09d2d8e9b9f@google.com> References: <55a49083-37f9-3766-1de9-9feea7428ac@google.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_NONE,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 Page migration of a VM_LOCKED page tends to fail, because when the old page is unmapped, it is put on the mlock pagevec with raised refcount, which then fails the freeze. At first I thought this would be fixed by a local mlock_page_drain() at the upper rmap_walk() level - which would have nicely batched all the munlocks of that page; but tests show that the task can too easily move to another cpu, leaving pagevec residue behind which fails the migration. So try_to_migrate_one() drain the local pagevec after page_remove_rmap() from a VM_LOCKED vma; and do the same in try_to_unmap_one(), whose TTU_IGNORE_MLOCK users would want the same treatment; and do the same in remove_migration_pte() - not important when successfully inserting a new page, but necessary when hoping to retry after failure. Any new pagevec runs the risk of adding a new way of stranding, and we might discover other corners where mlock_page_drain() or lru_add_drain() would now help. Signed-off-by: Hugh Dickins Acked-by: Vlastimil Babka --- v2: Delete suggestion of sysctl from changelog, per Vlastimil. mm/migrate.c | 2 ++ mm/rmap.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/mm/migrate.c b/mm/migrate.c index f4bcf1541b62..e7d0b68d5dcb 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -251,6 +251,8 @@ static bool remove_migration_pte(struct page *page, struct vm_area_struct *vma, page_add_file_rmap(new, vma, false); set_pte_at(vma->vm_mm, pvmw.address, pvmw.pte, pte); } + if (vma->vm_flags & VM_LOCKED) + mlock_page_drain(smp_processor_id()); /* No need to invalidate - it was non-present before */ update_mmu_cache(vma, pvmw.address, pvmw.pte); diff --git a/mm/rmap.c b/mm/rmap.c index 5442a5c97a85..714bfdc72c7b 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1656,6 +1656,8 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, * See Documentation/vm/mmu_notifier.rst */ page_remove_rmap(subpage, vma, PageHuge(page)); + if (vma->vm_flags & VM_LOCKED) + mlock_page_drain(smp_processor_id()); put_page(page); } @@ -1930,6 +1932,8 @@ static bool try_to_migrate_one(struct page *page, struct vm_area_struct *vma, * See Documentation/vm/mmu_notifier.rst */ page_remove_rmap(subpage, vma, PageHuge(page)); + if (vma->vm_flags & VM_LOCKED) + mlock_page_drain(smp_processor_id()); put_page(page); } -- 2.34.1