Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3028521imm; Mon, 24 Sep 2018 14:23:51 -0700 (PDT) X-Google-Smtp-Source: ACcGV60cekIZsIEJYAGFC4iDV1tZERLb4h+Ev6Tl7PsXKHvJXJys6Ii2EWehbIyuQ5HyzWqqWQXJ X-Received: by 2002:a17:902:7c15:: with SMTP id x21-v6mr523871pll.157.1537824231088; Mon, 24 Sep 2018 14:23:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537824231; cv=none; d=google.com; s=arc-20160816; b=uiqPzZJIgoNb9zP7Dr0b1OIhzs9ty7J+rqdlhqVuRWSC9WJU1b+CFHMjJlDBfIfHUQ gVkHhkLG5ABs3AoAUF07GhFzrC079A+qJSMRVHU7QOJF2oGgfiKAO4lekZqAyoYys52p 19Nv35JxgIXveViNIrxp+yg5zkzLNEBbEEN3gSKg3OMkGRX5eYWGk/pbmPTFSpBB6+2x nJrS7kdOxhcId0Vvrv6blY7ty6sxkQ0on4DzCnzhIv0owpdnMyI06NqVXOPdIH1wwqcP ymSrC5jPvXD//qbYjC3RU53eK7uS5CPImhWkAChDMI6O786CCUuFU+SGGOSSJo80M/Bf jd0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=+JzskV5OtzOG0m1p4s2/K6OdbQFGlvwNJc0p9Vcg3Ug=; b=GSlkDD8NCzWjlqs+5l+rgMwRg7jdPLSdRKYTCku2R1RdChT6e7BEmhWU9JXGDUF65j BxLn++F3dTe4fujJh9wCraoCbyo4ddvIVW7/EhhITFxZISj5RA4OhLvEBWoPgh2k1sJ2 kDugeHFw5x3DKclcPqo8v6TKaa2m+lolh/gE7Q60NF51FtkGdO0pudWaL27DHvAIx71I I7PUq2x0CS9lJnOdUE6sAqVk547gTpKpI+rn3yXshXJbof64yVFE/0wyG4k+qW0Z8oH/ aqR5z/+XELL06S5O4DkIwIvfP2txLPI6PYFvElNPG2OMJlqiwMGPFcfbFeZZY18wpQUG OF+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=fVwFHXTn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t10-v6si395631pgj.167.2018.09.24.14.23.35; Mon, 24 Sep 2018 14:23:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=fVwFHXTn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728569AbeIYD1B (ORCPT + 99 others); Mon, 24 Sep 2018 23:27:01 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:36897 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726227AbeIYD1B (ORCPT ); Mon, 24 Sep 2018 23:27:01 -0400 Received: by mail-wm1-f65.google.com with SMTP id n11-v6so11447832wmc.2 for ; Mon, 24 Sep 2018 14:22:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=+JzskV5OtzOG0m1p4s2/K6OdbQFGlvwNJc0p9Vcg3Ug=; b=fVwFHXTn9yPZU7Lmid16eukQPQe8o3I4e4Z2KYtpDm7xbaPe6w4rGMhikgUL3dCJy9 JfHFNHUl0e7C08c1pyf/V9iHbsx445uaMEA6jgKYeRzpkV/uLeruMl7rqsVCrJaN7yFI 30vec1xFmYxUWF9OK3b1cChuZLLAL/G6BZH1JKXP8uDlx1e6rMc1iYRCLw8R9uSObJ7y 2haDxgqo4ZhHG+diiEwhM7HXguaC07wO4y9iexYu97bCTn2SbVJ+FHW3z85glSQBggNB sk21uxYbXmTLZMOKVtt0b+aLWg/ttga2HL4BMxRyy8ZkZOOLYQsP2KdALm/b6GesMV/w xD6A== 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:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=+JzskV5OtzOG0m1p4s2/K6OdbQFGlvwNJc0p9Vcg3Ug=; b=JUO6spR26usiKaU322l5EiN04UZgn5HPqCR6xRmSVVhnOx7e0KXnTLZ7ZbTSALuBxN uQm6ZbCaR33mUlNTWjWKfw7STykhRaKilTzAu+uXaLAQ1KLTxB/LEL8JkEdVRKOFOR5o aQ0mi1CmCnwcwglBlzFEY9OyCCq0F6lpQqaDHh3SIGVunlAkW0H096nyI3VunZ+/VppY w2I/sRPqnOeseFQPmNTTp3YwO911lM84hggLEEQJSZDJtOY33tNx98yyzqf5oS9rCO/u 7fUqW0C8B9AyAD3jIpeZ/o4Utv3kE6lUlZQZv4IRpPVDo9Dwf50GvbpbIeI16m6AhXiF GRhQ== X-Gm-Message-State: ABuFfojoZFFHfP26sDUAdkb+IwICwCnIZi5imKejbjiqKDYiIK5hsYxJ Nbnm68bOTO4YsodC0J0L42Y9ZQ== X-Received: by 2002:a1c:b743:: with SMTP id h64-v6mr162457wmf.26.1537824169383; Mon, 24 Sep 2018 14:22:49 -0700 (PDT) Received: from kshutemo-mobl1.localdomain ([178.121.218.92]) by smtp.gmail.com with ESMTPSA id 88-v6sm248737wrf.95.2018.09.24.14.22.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Sep 2018 14:22:48 -0700 (PDT) Received: by kshutemo-mobl1.localdomain (Postfix, from userid 1000) id 40B7E3005E0; Tue, 25 Sep 2018 00:22:47 +0300 (+03) Date: Tue, 25 Sep 2018 00:22:47 +0300 From: "Kirill A. Shutemov" To: Yury Norov Cc: Andrew Morton , Al Viro , Dan Williams , Huang Ying , "Michael S . Tsirkin" , Michel Lespinasse , Souptick Joarder , Willy Tarreau , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH] mm: fix COW faults after mlock() Message-ID: <20180924212246.vmmsmgd5qw6xkfwh@kshutemo-mobl1> References: <20180924130852.12996-1-ynorov@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180924130852.12996-1-ynorov@caviumnetworks.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 24, 2018 at 04:08:52PM +0300, Yury Norov wrote: > After mlock() on newly mmap()ed shared memory I observe page faults. > > The problem is that populate_vma_page_range() doesn't set FOLL_WRITE > flag for writable shared memory in mlock() path, arguing that like: > /* > * We want to touch writable mappings with a write fault in order > * to break COW, except for shared mappings because these don't COW > * and we would not want to dirty them for nothing. > */ > > But they are actually COWed. The most straightforward way to avoid it > is to set FOLL_WRITE flag for shared mappings as well as for private ones. Huh? How do shared mapping get CoWed? In this context CoW means to create a private copy of the page for the process. It only makes sense for private mappings as all pages in shared mappings do not belong to the process. Shared mappings will still get faults, but a bit later -- after the page is written back to disc, the page get clear and write protected to catch the next write access. Noticeable exception is tmpfs/shmem. These pages do not belong to normal write back process. But the code path is used for other filesystems as well. Therefore, NAK. You only create unneeded write back traffic. -- Kirill A. Shutemov