Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3944743pxb; Fri, 11 Feb 2022 11:13:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJxB6bJDrJQbtZBjk8+2FlvMr6EhOFaEHrwSwXw6wtSWcYNULJInL4qCpIL223XeDPAlPcKm X-Received: by 2002:aa7:99c9:: with SMTP id v9mr3155175pfi.8.1644606790004; Fri, 11 Feb 2022 11:13:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644606789; cv=none; d=google.com; s=arc-20160816; b=Im0+OPcEYvDsGBw9zWdGmJz9t2qRO4S066zE3VEVu+fPOJPSnDYUksUT/agBq086hs 7Yj03QskV9NFCDQKq4LYiXifAe+vk2iZzLy7a2XtD3oHD2pc0woaZuzBgbvbC+S0av58 huOSSLVS2QD8CoUPbiqJnNWVtiQo/1itSwPv9s8Z37EN735hnBmHatEUCK3HaGOBz5f0 QNsRz5Qb7Rt4cWYXU4ATYpPjBB+rsttHK65cyj9e12pzyQGIh8zmBm0kpF22TPCJUlvE KXx7+KSnlTHCyj8SsW1J4Qq9tagKKKtw9y9BO+eX6wCBpGvY6OVyxsSqcUqV60FIDyTl q4wQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=JG6VCjeiAkeUL6Rpz2LpHri59dxNDgRuJeCG5zsYiLw=; b=CNmFOBei69+HmM/8Cc78hfux4NL3zKFd1N2KEZxuZjqAzyrJsnzhNVObUV+f1Ieufx 1oA125xXW7Lr6q9ZXFZkscf7grUEfV9wHHkwxfl/J0GNRFQhmr+0ab91JqX4ybK143JP h8E9QVVzC/PqhZis4YPcBpzH2voufh0Oxr+8q734rzqXIT/IFluBwbTPWYkC/hEgUC9m PbRUxVgI3mTSDh7tlNtROBP67xmyLXhtyXa31hQ4X09HJGiidBRf3d7FEDgTZzCXWy+a y3bxjh26zw1JYzp0GTe1WNvok2H0XrZSQLdwhCaq3NBM3VRc6vc9w8Iw04BP4AgnpZSX hHlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=c+bwZ0OX; dkim=neutral (no key) header.i=@suse.cz; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d8si22051510pgc.520.2022.02.11.11.12.53; Fri, 11 Feb 2022 11:13:09 -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=@suse.cz header.s=susede2_rsa header.b=c+bwZ0OX; dkim=neutral (no key) header.i=@suse.cz; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351702AbiBKQpd (ORCPT + 99 others); Fri, 11 Feb 2022 11:45:33 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:46352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351686AbiBKQpa (ORCPT ); Fri, 11 Feb 2022 11:45:30 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E436D102 for ; Fri, 11 Feb 2022 08:45:28 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 37F1D210E2; Fri, 11 Feb 2022 16:45:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1644597927; h=from:from:reply-to: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; bh=JG6VCjeiAkeUL6Rpz2LpHri59dxNDgRuJeCG5zsYiLw=; b=c+bwZ0OXGT0PuuChKSsjvdI2ZwQGyZUoSx8Y+jlbLt0Lmme4ZOZ4Wlr8U9wTbcwB+VHCJ3 hXBIA43sdeTPtwcBN5bB/cSef7K387eqIGQ9vjAjHFudxnp2C9PPJRgCmpSOvk+eYx1+m3 ayC+yq4dPnPS1i9xm1nnOOhiyf82oJk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1644597927; h=from:from:reply-to: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; bh=JG6VCjeiAkeUL6Rpz2LpHri59dxNDgRuJeCG5zsYiLw=; b=KF+weUUfsrjBr/2qs5X4rNiVuE8C6g+q4n2SDEBVfvfZM0DFXmKI4GjYsqvmeivgmu9sxj 925HVhAQHm+tosCQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id EDC7313C9E; Fri, 11 Feb 2022 16:45:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ppodOaaSBmKydAAAMHmgww (envelope-from ); Fri, 11 Feb 2022 16:45:26 +0000 Message-ID: <2ec49f65-fe4e-26a0-4059-c18e6dab0af4@suse.cz> Date: Fri, 11 Feb 2022 17:45:26 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.1 Subject: Re: [PATCH 07/13] mm/munlock: mlock_pte_range() when mlocking or munlocking Content-Language: en-US To: Hugh Dickins , Andrew Morton Cc: Michal Hocko , "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 References: <8e4356d-9622-a7f0-b2c-f116b5f2efea@google.com> <8bc3ee8c-7f1-d812-7f22-4f9f6d436bc@google.com> From: Vlastimil Babka In-Reply-To: <8bc3ee8c-7f1-d812-7f22-4f9f6d436bc@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 2/6/22 22:42, Hugh Dickins wrote: > Fill in missing pieces: reimplementation of munlock_vma_pages_range(), > required to lower the mlock_counts when munlocking without munmapping; > and its complement, implementation of mlock_vma_pages_range(), required > to raise the mlock_counts on pages already there when a range is mlocked. > > Combine them into just the one function mlock_vma_pages_range(), using > walk_page_range() to run mlock_pte_range(). This approach fixes the > "Very slow unlockall()" of unpopulated PROT_NONE areas, reported in > https://lore.kernel.org/linux-mm/70885d37-62b7-748b-29df-9e94f3291736@gmail.com/ > > Munlock clears VM_LOCKED at the start, under exclusive mmap_lock; but if > a racing truncate or holepunch (depending on i_mmap_rwsem) gets to the > pte first, it will not try to munlock the page: leaving release_pages() > to correct it when the last reference to the page is gone - that's okay, > a page is not evictable anyway while it is held by an extra reference. > > Mlock sets VM_LOCKED at the start, under exclusive mmap_lock; but if > a racing remove_migration_pte() or try_to_unmap_one() (depending on > i_mmap_rwsem) gets to the pte first, it will try to mlock the page, > then mlock_pte_range() mlock it a second time. This is harder to > reproduce, but a more serious race because it could leave the page > unevictable indefinitely though the area is munlocked afterwards. > Guard against it by setting the (inappropriate) VM_IO flag, > and modifying mlock_vma_page() to decline such vmas. > > Signed-off-by: Hugh Dickins Acked-by: Vlastimil Babka > @@ -162,8 +230,7 @@ static int mlock_fixup(struct vm_area_struct *vma, struct vm_area_struct **prev, > pgoff_t pgoff; > int nr_pages; > int ret = 0; > - int lock = !!(newflags & VM_LOCKED); > - vm_flags_t old_flags = vma->vm_flags; > + vm_flags_t oldflags = vma->vm_flags; > > if (newflags == vma->vm_flags || (vma->vm_flags & VM_SPECIAL) || Nit: can use oldflags instead of vma->vm_flags above?