Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp582965pxb; Wed, 27 Jan 2021 15:50:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJwDeXhKb+RBp/vDg+rQtnA+9hNO73uqJfHM2kF20s3BnpV9+X21cT/hYfbAPgw3oYas+OX6 X-Received: by 2002:a05:6402:34c3:: with SMTP id w3mr11430366edc.3.1611791424435; Wed, 27 Jan 2021 15:50:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1611791424; cv=pass; d=google.com; s=arc-20160816; b=yoaBfKTNAImL+FCkvUKlsBtXEyK1ITwe5pLCiQ2KcyJOAmNI1tOoiJ47YhGJTeOHEY 5G5CuMNvMoIxvcwTwLhppbquBlqwzpoZixR+iy3HR3VIZAW6nHlw9nVA1RAeRyqaskIz 1GvBD0ZN3iH63GezY03+PnC1rq1QzEhMYqk0M4/ocG29Y8rVXo3QNKOXFQ1aF00dx9n1 7xxHFAukijMT/kDUGTe4k99ZTUQIEHw0e49PcJv+fpcdNqDSA0yEiqN1IkHUX/xsrBaI JxBapuf2R2i9yphE2QiKGmoK0aRlpjfynSBQwxPwxI0qEitCN8B/1pHaovni/ZsjPSAt jZbA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-language :content-transfer-encoding:in-reply-to:user-agent:date:message-id :from:references:cc:to:subject:dkim-signature; bh=eJSFAr2JEbe7h5H5ZKMXourJbFlzzd2nOHX3it5Ie/s=; b=B7FrON2d6tACbnha4fDu+S25UlY6xJHHusJRY0L0zRlU316AcXvgbm4v7daquJIST4 ik1M+hzfIxYzqfq7itg3e/o/5h7ZGpYXef/MtTV7+mwYtzwnQO423h02FuZgS9Hv1+la V5gU6dGMfAjdUkVWkH9BSiQqDSiO8paX6uHW95kG5/WmRJJGxL80/IIloFKIJusO06t6 jrqwcSy9uq/VPj2k0ZsOniycyneVwP8DdhUAdLfstUuw6ilX3C42wM+irr1/T284qcZn 4KGaRAfj+yyKJ4VWFYOjNHENcLAU/soKhOKu2Vf443Hpb2cvtKJXejQLhmZTplsBfO7h RsCw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=xUuulsCX; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amd.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ba30si1810393edb.470.2021.01.27.15.49.59; Wed, 27 Jan 2021 15:50:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=xUuulsCX; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236360AbhA0LFk (ORCPT + 99 others); Wed, 27 Jan 2021 06:05:40 -0500 Received: from mail-bn8nam11on2056.outbound.protection.outlook.com ([40.107.236.56]:34016 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236393AbhA0LC5 (ORCPT ); Wed, 27 Jan 2021 06:02:57 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cZRlugVJTiL8l9S/qpeUQ6za2AEhFLu9YZAan3/gLH4Kfa6DzTgXpWmjAQlfzC/JrrZI2peCld8pOUoizcsZ9c0gISsU2MB+2fRnUkLfQiBGj+GURehVL9S6OXsySUaFt5Z0Nr9hlejhmN0LzIC6RO76ml6scU7Dvj62v5EkrpbwQa31FZyZnHhfp2VzuEqdV2N9mfilMoYfXcEBg4IydgXdfrEP+4s0s5H5AWhSOlTy0fVviXG4eAdR8zpkW1cOOShbLbYCOA3UcmSLKmEhAGxa4Q7rHpw2XMDw3F8bRMWQdiyPfqEDYARbPcRnACQIKAezxYMtO+eb2zcQzu3mnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eJSFAr2JEbe7h5H5ZKMXourJbFlzzd2nOHX3it5Ie/s=; b=jI/s0bVXCKcDTvev6SEdqBKHaToy59EgdmzuRbh+dr0w78j3W5KpcytBPVs+mkDANY/BW1LkzFM2WLvr2U+DCv4xDxWQinloIcwLuPauaA0gab08DW1UP3ew5KafnO+c2NKgWEN5ZK3o3TxPijQFAXhqKXk8sE++RPp4cWIGufcMkS6McW6U7q3YuxRm9QJSc0vl8x0V+2GsXk3gj7tj8jBSe+hYIOsGHeEAO2N0bemDCzE8oLp1jEgTTHKsD/m04HH/At7GZ4V32Rl2XUAcDt29VmVYodVrpABVKHguvNC3fr7en8kZJuXyjieCWZkTp86gX2Iv4XBBXe8Rn3CsbA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eJSFAr2JEbe7h5H5ZKMXourJbFlzzd2nOHX3it5Ie/s=; b=xUuulsCXSyD4Ai5BmxyB6iOl7Xo+Fh52VMTkslfpPLPlDnYviPtO5gMm2ojw87lolPZFJufthUiczkLasfih6A9iOre3ddlOB0CWfG5DlGXGBJ4ZUqVds+A+Kvz5vwPdtZi2zlebG6720NOhDYIlGgZ7ZXJjTBAMTy3UuyUsviM= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=amd.com; Received: from MN2PR12MB3775.namprd12.prod.outlook.com (2603:10b6:208:159::19) by MN2PR12MB3901.namprd12.prod.outlook.com (2603:10b6:208:16c::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.12; Wed, 27 Jan 2021 11:02:03 +0000 Received: from MN2PR12MB3775.namprd12.prod.outlook.com ([fe80::44f:9f01:ece7:f0e5]) by MN2PR12MB3775.namprd12.prod.outlook.com ([fe80::44f:9f01:ece7:f0e5%3]) with mapi id 15.20.3784.019; Wed, 27 Jan 2021 11:02:03 +0000 Subject: Re: [PATCH] procfs/dmabuf: Add /proc//task//dmabuf_fds To: Michal Hocko , Jann Horn Cc: Kalesh Singh , Suren Baghdasaryan , Minchan Kim , Greg Kroah-Hartman , Hridya Valsaraju , kernel-team , Alexey Dobriyan , Jonathan Corbet , Sumit Semwal , Mauro Carvalho Chehab , Andrew Morton , Kees Cook , Alexey Gladkov , Szabolcs Nagy , "Eric W. Biederman" , Daniel Jordan , Michel Lespinasse , Bernd Edlinger , Andrei Vagin , Yafang Shao , Hui Su , kernel list , linux-fsdevel , "open list:DOCUMENTATION" , Linux Media Mailing List , dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Jeffrey Vander Stoep , Linux API References: <20210126225138.1823266-1-kaleshsingh@google.com> From: =?UTF-8?Q?Christian_K=c3=b6nig?= Message-ID: Date: Wed, 27 Jan 2021 12:01:55 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [2a02:908:1252:fb60:be8a:bd56:1f94:86e7] X-ClientProxiedBy: AM0PR04CA0059.eurprd04.prod.outlook.com (2603:10a6:208:1::36) To MN2PR12MB3775.namprd12.prod.outlook.com (2603:10b6:208:159::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [IPv6:2a02:908:1252:fb60:be8a:bd56:1f94:86e7] (2a02:908:1252:fb60:be8a:bd56:1f94:86e7) by AM0PR04CA0059.eurprd04.prod.outlook.com (2603:10a6:208:1::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.17 via Frontend Transport; Wed, 27 Jan 2021 11:01:58 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: bad9c4f3-c6e6-4e5c-d456-08d8c2b2f97c X-MS-TrafficTypeDiagnostic: MN2PR12MB3901: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1wVDOw4Xvpw7e8+6T0HEhvyA90mTxhBqvvxZ3PLJ1G1+rSwQASeTXpQv25BzetjqTKMhsh0HI8b5LRpqd688buj2kTH35d38L+LGFaPHs74gqYZ5FZXHtg/oypwqZYUWDN6GTjkpGdb6zbOb9utlg0vBDF0fuK1drREVlRS/PBBAyi701j64BPHuS8R3JBsd3i3vYDfDA2EOzHnhm0O4cQkoR9waKNTmSVs7laPg0Z1cQqG9ttzz4iwh8/+komushJogA/P7soOewAt2MTw+CPh1C9fRbaPs1J7fddNk2L+WRfNz+R+ntDuR1Py9uac4tIWnA1GTMzPHvHltXywbFS4mAVWhJwbLq1r0CQapEMtIw96OsvQFvlb2naiBPlmNp62yhLyeiFqaM5IfsMFxUcPHxyRQkbyx3KboWkuAr7cHB9qemOEWXuvkc7Q2gpyGxMsgUEVW7NmgRNigad6Rk5nLmyDlgcertUkQnA4qbvz8nP6eW3HL/FSsTWRzXkkd X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR12MB3775.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(346002)(376002)(39860400002)(396003)(366004)(2616005)(83380400001)(52116002)(66556008)(8676002)(2906002)(66476007)(31686004)(186003)(110136005)(66946007)(31696002)(34580700001)(16526019)(7416002)(6486002)(6666004)(478600001)(86362001)(4326008)(7406005)(54906003)(36756003)(53546011)(316002)(8936002)(5660300002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?S3FyQXFuaXpFYkFwbHZDYWtlMkgzQ0RhcXMxYzFaZjNVRmlhZHJsd293YUZ3?= =?utf-8?B?eDhkSEthUWFOZFZHM1RoNVdrc1hOSUx6MW9MaTRGc3VLLzNUL0lWTm1HRHhJ?= =?utf-8?B?b2tRYVAyb29XQlhWUklwNHEwWm1NQzNmMHJFMitIQ1gvajdFSjVlOTJ5bDNZ?= =?utf-8?B?Rk5QM2VYL0lNM0phMTRPak5lVDhrMVl0c0hKT0tDV3dHMkFBa0VkbzVvNUlM?= =?utf-8?B?emttbzlvRWlmSHdQRjZtMDFId1BWYTRLbHBOL0V1eVZjMEFNUS85a1hJaUdp?= =?utf-8?B?VTFmbjRhcWxoWlR2TkVQMWhNbGxCajNMYTRlRm1iaytnR3puZzNaMklqVVkv?= =?utf-8?B?QitjQ1Q2ZjMvYzV2WU12K0VYdGEzWHVPbjBuc2FNS2hUUXBIUDd6QXdrWHBs?= =?utf-8?B?cndZR1JOanF4MHpMYndUYVJpRHVmQ0lvVjFPekxNTWk1blUzb0QxbUsxNWpV?= =?utf-8?B?M3BPdUZ2YUhqTlhkcEhDWFFsSG1lVFpOMGFNQVd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bVZaRktDN1paQlhncjJqSklJdXgwaTdBdkRt?= =?utf-8?B?cjVDV1dzaUw2aWxQNHdHcDFxRWVzdWNHUHJRNUVLSlloRlBFMFZXakQ5TUpS?= =?utf-8?B?VVJ5VWljU1FnRlpkZFE3a0FaQjR2Z2pmbkU3VkJsZlMxWlhibVEvbzB2MjE3?= =?utf-8?B?UEZmQT09?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: bad9c4f3-c6e6-4e5c-d456-08d8c2b2f97c X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB3775.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2021 11:02:03.0263 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 3FTX22ttGIfist2bUXl/WF2wlrwOp6ZM56na/czmblq8mAAClDiHaVeQL0oAg2dl X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3901 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 27.01.21 um 11:57 schrieb Michal Hocko: > On Wed 27-01-21 11:47:29, Jann Horn wrote: >> +jeffv from Android >> >> On Tue, Jan 26, 2021 at 11:51 PM Kalesh Singh wrote: >>> In order to measure how much memory a process actually consumes, it is >>> necessary to include the DMA buffer sizes for that process in the memory >>> accounting. Since the handle to DMA buffers are raw FDs, it is important >>> to be able to identify which processes have FD references to a DMA buffer. >> Or you could try to let the DMA buffer take a reference on the >> mm_struct and account its size into the mm_struct? That would probably >> be nicer to work with than having to poke around in procfs separately >> for DMA buffers. > Yes that would make some sense to me as well but how do you know that > the process actually uses a buffer? If it mmaps it then you already have > that information via /proc//maps. My understanding of dma-buf is > really coarse but my impression is that you can consume the memory via > standard read syscall as well. How would you account for that. Somewhat correct. This interface here really doesn't make sense since the file descriptor representation of DMA-buf is only meant to be used for short term usage. E.g. the idea is that you can export a DMA-buf fd from your device driver, transfer that to another process and then import it again into a device driver. Keeping a long term reference to a DMA-buf fd sounds like a design bug in userspace to me. > [...] > Skipping over a large part of your response but I do agree that the > interface is really elaborate to drill down to the information. > >> I'm not convinced that introducing a new procfs file for this is the >> right way to go. And the idea of having to poke into multiple >> different files in procfs and in sysfs just to be able to compute a >> proper memory usage score for a process seems weird to me. "How much >> memory is this process using" seems like the kind of question the >> kernel ought to be able to answer (and the kernel needs to be able to >> answer somewhat accurately so that its own OOM killer can do its job >> properly)? > Well, shared buffers are tricky but it is true that we already consider > shmem in badness so this wouldn't go out of line. Kernel oom killer > could be more clever with these special fds though and query for buffer > size directly. Some years ago I've proposed an change to improve the OOM killer to take into account how much memory is reference through special file descriptors like device drivers or DMA-buf. But that never want anywhere because of concerns that this would add to much overhead to the OOM killer. Regards, Christian.