Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1037099ybe; Wed, 11 Sep 2019 08:25:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqy/w1/2kCJdcjXELiWtmDLz8JKotYjv9ToZovukvmZXGMP46ByPJ4oc8X2v3XKgGrp/+kVZ X-Received: by 2002:a50:ab49:: with SMTP id t9mr33703335edc.301.1568215543921; Wed, 11 Sep 2019 08:25:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568215543; cv=none; d=google.com; s=arc-20160816; b=KY0ibPvB8nJ6rs5nsl+MBX/GvbbASN3Bl0rzaS64PFkgDH2/aHgxWmz7LFsHpxPYkm C4YO6pyoZEmpPCaFI41YA1ruHrafiBapa5QlVpuBanxR8W43qUi90QsKF6ACa57G4azl bvSYL0RYrodzAw1nIvGoDPlBl0P4rOOPPaxfHYrCJCODvJ6M35fk0pCS8zZQzxD0doOi ymybmF9UNIIijeyqK76Gr0GgR3Q1r0kuuGZY6gGQnffYs9kcYQk/tPh2ESN97xjsLNMn lXIpEiLksSYQoipmRQrCWBI+Mf5HcNUtRS0mHamHKRg4kv7jsGr7WnuMu6JEdT5dGts5 KyAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=AOVlbnJEW5/MZpuAAJ+LYFT9rQ5n+q+K+8j4LdDBV3M=; b=MyHXUu9VGQF1Usa6u6jxXbRK92wKRDsWXN/dclNfZ3LIV6rm4ODvMjviZZBACtmzyB gjUENrmPHMaQtHkF0QkUdEXMzZY//NYr12rVXpwPUf/hp1shg8hiSO+3pCcfDyE77vkg bGuc3FifAEczKN+Z9G+84YzHPI6YO0YCHB4p+hW7r8S8L+rggge11I7gLmLsr1VzcjwG 1JTw4ICl3+nbaf6Mbiqn7NnujIeMRconrBKulrOYMLd8bFs5KIrNrojNsLbJ47eIMT2S I1B0TLeklGWvj1T80QUNwo2UFtkMP56uX5zsxoM459qZlEIDBCg/SOqWj8GbuHr+z3ev GAag== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z2si12921754edq.361.2019.09.11.08.25.20; Wed, 11 Sep 2019 08:25:43 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728487AbfIKPXX (ORCPT + 99 others); Wed, 11 Sep 2019 11:23:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44502 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726510AbfIKPXX (ORCPT ); Wed, 11 Sep 2019 11:23:23 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C7BEF1DA2; Wed, 11 Sep 2019 15:23:22 +0000 (UTC) Received: from [10.10.125.194] (ovpn-125-194.rdu2.redhat.com [10.10.125.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9212C60BEC; Wed, 11 Sep 2019 15:23:21 +0000 (UTC) Subject: Re: [RFC PATCH] Add proc interface to set PF_MEMALLOC flags To: Tetsuo Handa References: <20190909162804.5694-1-mchristi@redhat.com> <5D76995B.1010507@redhat.com> Cc: axboe@kernel.dk, James.Bottomley@HansenPartnership.com, martin.petersen@oracle.com, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Linux-MM From: Mike Christie Message-ID: <5D791169.2090807@redhat.com> Date: Wed, 11 Sep 2019 10:23:21 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.71]); Wed, 11 Sep 2019 15:23:23 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/10/2019 05:12 PM, Tetsuo Handa wrote: > On 2019/09/10 3:26, Mike Christie wrote: >> Forgot to cc linux-mm. >> >> On 09/09/2019 11:28 AM, Mike Christie wrote: >>> There are several storage drivers like dm-multipath, iscsi, and nbd that >>> have userspace components that can run in the IO path. For example, >>> iscsi and nbd's userspace deamons may need to recreate a socket and/or >>> send IO on it, and dm-multipath's daemon multipathd may need to send IO >>> to figure out the state of paths and re-set them up. >>> >>> In the kernel these drivers have access to GFP_NOIO/GFP_NOFS and the >>> memalloc_*_save/restore functions to control the allocation behavior, >>> but for userspace we would end up hitting a allocation that ended up >>> writing data back to the same device we are trying to allocate for. >>> >>> This patch allows the userspace deamon to set the PF_MEMALLOC* flags >>> through procfs. It currently only supports PF_MEMALLOC_NOIO, but >>> depending on what other drivers and userspace file systems need, for >>> the final version I can add the other flags for that file or do a file >>> per flag or just do a memalloc_noio file. > > Interesting patch. But can't we instead globally mask __GFP_NOFS / __GFP_NOIO > than playing games with per a thread masking (which suffers from inability to > propagate current thread's mask to other threads indirectly involved)? If I understood you, then that had been discussed in the past: https://www.spinics.net/lists/linux-fsdevel/msg149035.html We only need this for specific threads which implement part of a storage driver in userspace. > >>> +static ssize_t memalloc_write(struct file *file, const char __user *buf, >>> + size_t count, loff_t *ppos) >>> +{ >>> + struct task_struct *task; >>> + char buffer[5]; >>> + int rc = count; >>> + >>> + memset(buffer, 0, sizeof(buffer)); >>> + if (count != sizeof(buffer) - 1) >>> + return -EINVAL; >>> + >>> + if (copy_from_user(buffer, buf, count)) > > copy_from_user() / copy_to_user() might involve memory allocation > via page fault which has to be done under the mask? Moreover, since > just open()ing this file can involve memory allocation, do we forbid > open("/proc/thread-self/memalloc") ? I was having the daemons set the flag when they initialize.