Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp607629ybt; Sat, 13 Jun 2020 15:21:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0OgSIzjPGA36A5NkeP7mKSSrxZm+uFmV1v0vEtaPAKJzGxGeaJWWtf2x6Lj5GX369APR/ X-Received: by 2002:a17:906:2893:: with SMTP id o19mr16983276ejd.231.1592086873215; Sat, 13 Jun 2020 15:21:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592086873; cv=none; d=google.com; s=arc-20160816; b=nfRjtftTQ2TZuSjpHaAsg/fmoAUx+PLcyITomhYe3r8C4vlQBiJSyLvxYjQ38v0JLi Ej5WktEyk1oE0ATw3y+aIbqkbNfUy6eKWh2pQH8noDdSwCX8p8mqXCx7OAB/6IU6syO4 w7lLKVixuTpr5sNOGh8VGObMDA/Dt0A/LYl7TVEcbxicX7TFgWb72rtArm/ZBF2tyeEo vWH2W/NlEf+iIeQe8hvbLvRxJZjC/9TXoxpJ1INflUTLDEpI3YO29vUjOQJLlkhEdN1y 3cc3eQHdOMWHBDsA8olk/0XU23+4mKayK4mRoDErUEvBZV95AgybAXXTElityWs+oCjG ofGw== 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=i5R8hGtupULp/LcVllMJa3o6cOtVEr3gO4/vRAJX748=; b=jCQqtnalB/xoMhDngw4QKRupcVkW3FzbjVO/YYZnwu09G8zG4alCNHRsIYRQbYjcmV dSxsk3IbJ8ArebG7NhXjDuId6HvNcSGyAUJTCionqhcT+52Pf3fPk6YZtIKmeXPJSE/s HRBsVkGHkROymkF5twrQ4qlliLPikJsc7RIfWQfy/hznHvDu1lPREiV/ohochvnc/JDG 8iZ2WZz/ofRb5sFJjFiZhy6Fog2+DWHQIn45Tq+kHk6YHa5CAp7JIiKp36/UoFJDVJHV qiNoGOZgB84ppZdlCJ2CVLwxweclDB26hkgWV9h4+e2KHEGjMEkVOmKafhwrRsjdhRAi Ks6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=p2eUytlx; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a22si6373291ejr.529.2020.06.13.15.20.51; Sat, 13 Jun 2020 15:21:13 -0700 (PDT) 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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=p2eUytlx; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726624AbgFMWRD (ORCPT + 99 others); Sat, 13 Jun 2020 18:17:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726304AbgFMWRD (ORCPT ); Sat, 13 Jun 2020 18:17:03 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68F25C03E96F for ; Sat, 13 Jun 2020 15:17:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=i5R8hGtupULp/LcVllMJa3o6cOtVEr3gO4/vRAJX748=; b=p2eUytlxPR3iPhCZ0KngWubLeM zm42uSEM457KwFdzZwuav82XyMjwbtox4oV2A4A7HWqClcOWGfRVHS8sws0VVU4wIwBUMiX3SchMa uFsVAnalBx9WEVFAzcZXqpv9WFHV8b+hgtAOboKUtPFEXg4eG9TUMX49nAhU//h8ikPV8zNFiG0RK 1HrfnY9Rs2dfhZxFE1dxgnu9LHNrRD2fjo1qVZMlVFRfKn7GYIdvLS5+MJevtTuAeMYUZa1jkPciM S9djRDiMdXSS+XfnqqG0iJcgzjHUchMmDWrv//HthfDc+4SyFQHln1Z268xc+L1VCvcM432Vnl2YU /WANM4aQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jkESM-000668-Rm; Sat, 13 Jun 2020 22:16:54 +0000 Date: Sat, 13 Jun 2020 15:16:54 -0700 From: Matthew Wilcox To: Arnd Bergmann Cc: afzal mohammed , Russell King - ARM Linux admin , Linus Walleij , "linux-kernel@vger.kernel.org" , Linux-MM , Linux ARM , Nicolas Pitre , Catalin Marinas , Will Deacon Subject: Re: [RFC 1/3] lib: copy_{from,to}_user using gup & kmap_atomic() Message-ID: <20200613221654.GO8681@bombadil.infradead.org> References: <9e1de19f35e2d5e1d115c9ec3b7c3284b4a4e077.1591885760.git.afzal.mohd.ma@gmail.com> <20200612135538.GA13399@afzalpc> <20200613120432.GA5319@afzalpc> 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 Sat, Jun 13, 2020 at 10:45:33PM +0200, Arnd Bergmann wrote: > On Sat, Jun 13, 2020 at 2:04 PM afzal mohammed wrote: > > Observation is that max. pages reaching copy_{from,to}_user() is 2, > > observed maximum of n (number of bytes) being 1 page size. i think C > > library cuts any size read, write to page size (if it exceeds) & > > invokes the system call. Max. pages reaching 2, happens when 'n' > > crosses page boundary, this has been observed w/ small size request > > as well w/ ones of exact page size (but not page aligned). > > Right, this is apparently because tmpfs uses shmem_file_read_iter() to > copy the file pages one at a time. generic_file_buffered_read() seems > similar, to copying between an aligned kernel page and address in > user space that is not page aligned would be an important case to > optimize for. This is kind of the nature of the page cache. The kernel doesn't necessarily have contiguous memory in the page cache, so it's going to be split on page boundaries. This is going to change with my THP series (I haven't actually changed generic_file_buffered_read(), but it'll come later). > > Quickly comparing boot-time on Beagle Bone White, boot time increases > > by only 4%, perhaps this worry is irrelevant, but just thought will > > put it across. > > 4% boot time increase sounds like a lot, especially if that is only for > copy_from_user/copy_to_user. In the end it really depends on how well > get_user()/put_user() and small copies can be optimized in the end. The write path should also be paid attention to. Look at generic_perform_write() which first calls iov_iter_fault_in_readable() (for the entire length of the write) and then actually does the copy later with iov_iter_copy_from_user_atomic(). So you're going to want to optimise the case where you access the same pages multiple times.