Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1135537ybv; Thu, 13 Feb 2020 16:37:00 -0800 (PST) X-Google-Smtp-Source: APXvYqySoDHlnalZeYMftj77RpdRCY5UPzql2QACLlRGFitxusjHlFPPDYdhKhQ2hEIKeC8egvzj X-Received: by 2002:a05:6830:1498:: with SMTP id s24mr172757otq.79.1581640620219; Thu, 13 Feb 2020 16:37:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581640620; cv=none; d=google.com; s=arc-20160816; b=FzWyiJKZoxar9ji6QU+CgHJqEm2xXJjLp7iOFk5C1u4/WlUXiIO9Z7K3Z78AOuJwt8 vmTAkoTkd33d24oYZds0Uy8B2YvQZRaANse5fdWdvLsNcm8tziUWtDt+4ofdUzyf57cL rhC0XApeVszbg5Bvec7LVB9R/2FWD8LZcNyFE1VBAtJcXKQWavtwJtZThaMv9bBCQ5FI EuEA5MhgMZjG3a8zQLqdJRKxTJyS22SUvwcA6KAqe/GVEaS72Qk8/qslEnQ97Fd8NkwU WfLUp8unrwWmdD4TssTvT63vl5eojN/apJIUKH82HKOQEBfmsVHSi21atiDM9Yp0AKKe MZvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=4f0EZeoJlExzljE8pJVUxkTCYd/feIyLQps13jN8CxI=; b=Wm4hAy1iDBuj6G6za6MCEm55vsCM+pBYlwa+R+zegGk32qKZba+sYfPMhESGI1pSd0 CROLVvIIqEcEd7O9a4D1a7Mp2cZDtMvjJcOB7hmxmuZ0VwDMwgqTCCDiG4MP2rHyIabB 1R0s4ra77T4ijCyDDAQwBPxTverDHLIbkVaY2ASc5hFL0KZLa2FTyp0VyehtQiCwntUX FDG0gaqycsfaATCs0QiB5gCJvI6ujhJDknni8U4lB7HnIXQsgXH+eTC8O8hi5KsIIlqb aKJdNiPhSaQeaO51rTK8cVbWbysPqnPizSK3KVMM4EmlqE+JxoSINw+b0DHIrgsz6RVI 7JSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=PacGcFWD; 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 s20si1920443otp.4.2020.02.13.16.36.47; Thu, 13 Feb 2020 16:37:00 -0800 (PST) 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=PacGcFWD; 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 S1728137AbgBNAgV (ORCPT + 99 others); Thu, 13 Feb 2020 19:36:21 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:36538 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728012AbgBNAgV (ORCPT ); Thu, 13 Feb 2020 19:36:21 -0500 Received: by mail-lf1-f66.google.com with SMTP id f24so5585304lfh.3 for ; Thu, 13 Feb 2020 16:36:19 -0800 (PST) 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; bh=4f0EZeoJlExzljE8pJVUxkTCYd/feIyLQps13jN8CxI=; b=PacGcFWD/+hjRVHJiK+ORMA3HMJLTlsaB+Wjr9TLvq+iI0kdJnr0AbgEl5LQCXI/dw u9AoIP+FTxfxUXlA9Ps6lORc63DbyQgtlHqzF8v7joJKPBftimDS51TTAwiC6vIznm/0 oj1OBSd7sy4hEj+laIQEi6a29v5EbGZeacU7LrVOLyKscRyh8yKZarFWURNE/QpdxCNr nS6TAzXb5s9c4qXfgbfwka7AcihAZNSnsk4769Lij4sI/EPBL0iLtHUaT9LALPJXTIpS YBaGeA5YE3FxbqV/Yh7UmizHXUqeQcRE4l7+8MuaK+AeWHDHey6vx6GeeOE1ZuIPluZ6 SDIg== 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; bh=4f0EZeoJlExzljE8pJVUxkTCYd/feIyLQps13jN8CxI=; b=YW82tzczcdW61/wq62IUGIXOGPqE6AxO4aglOtcFbfHOJqIkHe6cvUMOpSVh0HD7em ieH9pmiDdi+RzW0CJ2PFwa9EIOUvi3cV8XauLlfBzCWsNLtAZyxuCH/G3prntvi3XvkB bd/R2s9vQRYZBX9CKE915LRijO4zE7l4DqQSHIzCFFphJDsoR1sBvlW5ZeQTItBgqwhM CyiA7l8MTdwzTRY7QdvabxzPJN//mbzGL5FIhGiMQyWSODaZyXR1/f6Gpal9aUIeq8Fg +omryNscLL7tqq/BL3d1+O2pK/zbQdI2bmTkKLnHN5R3L2PrUOoVi1mPn0Xqdh6uC7fK HBJA== X-Gm-Message-State: APjAAAVIxTbZpVm1Qw1i/oASydVWoCRaJaKF/PqS4f6Y1UEj9+ztnJ/R AUz1GeQCK/bcOsOKtT6bG8+YYw== X-Received: by 2002:ac2:4833:: with SMTP id 19mr261332lft.211.1581640578725; Thu, 13 Feb 2020 16:36:18 -0800 (PST) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id y2sm2437542ljm.28.2020.02.13.16.36.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2020 16:36:17 -0800 (PST) Received: by box.localdomain (Postfix, from userid 1000) id 1512C100F2C; Fri, 14 Feb 2020 03:36:40 +0300 (+03) Date: Fri, 14 Feb 2020 03:36:40 +0300 From: "Kirill A. Shutemov" To: Brian Geffon Cc: Andrew Morton , "Michael S . Tsirkin" , Arnd Bergmann , LKML , linux-mm , Linux API , Andy Lutomirski , Will Deacon , Andrea Arcangeli , Sonny Rao , Minchan Kim , Joel Fernandes , Yu Zhao , Jesse Barnes , Nathan Chancellor , Florian Weimer Subject: Re: [PATCH v4] mm: Add MREMAP_DONTUNMAP to mremap(). Message-ID: <20200214003640.yphbnjw7omsx2rje@box> References: <20200207201856.46070-1-bgeffon@google.com> <20200210104520.cfs2oytkrf5ihd3m@box> <20200213120813.myanzyjmpyzixghf@box> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 13, 2020 at 10:20:44AM -0800, Brian Geffon wrote: > Hi Kirill, > > > But if you do the operation for the VM_LOCKED vma, you'll have two locked > > VMA's now, right? Where do you account the old locked vma you left behind? > > You bring up a good point. In a previous iteration of my patch I had > it clearing the locked flags on the old VMA as technically the locked > pages had migrated. I talked myself out of that but the more I think > about it we should probably do that. Something along the lines of: > > + if (vm_flags & VM_LOCKED) { > + /* Locked pages would have migrated to the new VMA */ > + vma->vm_flags &= VM_LOCKED_CLEAR_MASK; > + if (new_len > old_len) > + mm->locked_vm += (new_len - old_len) >> PAGE_SHIFT; > + } > > I feel that this is correct. The only other possible option would be > to clear only the VM_LOCKED flag on the old vma leaving VM_LOCKONFAULT > to handle the MCL_ONFAULT mlocked situation, thoughts? Regardless I'll > have to mail a new patch because that part where I'm incrementing the > mm->locked_vm lost the check on VM_LOCKED during patch versions. Note, that we account mlock limit on per-VMA basis, not per page. Even for VM_LOCKONFAULT. > Thanks again for taking the time to review. I believe the right approach is to strip VM_LOCKED[ONFAULT] from the vma you left behind. Or the new vma. It is a policy decision. JFYI, we do not inherit VM_LOCKED on fork(), so it's common practice to strip VM_LOCKED on vma duplication. Other option is to leave VM_LOCKED on both VMAs and fail the operation if we are over the limit. But we need to have a good reason to take this path. It makes the interface less flexible. -- Kirill A. Shutemov