From owner-svn-src-all@freebsd.org Thu Jan 9 04:03:17 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id E78E6226A9A; Thu, 9 Jan 2020 04:03:17 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47tXXP5q80z4YmR; Thu, 9 Jan 2020 04:03:17 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C2FD522ECF; Thu, 9 Jan 2020 04:03:17 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 00943HVJ058729; Thu, 9 Jan 2020 04:03:17 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 00943HFL058728; Thu, 9 Jan 2020 04:03:17 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <202001090403.00943HFL058728@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Thu, 9 Jan 2020 04:03:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r356537 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 356537 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Jan 2020 04:03:18 -0000 Author: kevans Date: Thu Jan 9 04:03:17 2020 New Revision: 356537 URL: https://svnweb.freebsd.org/changeset/base/356537 Log: shmfd: posix_fallocate(2): only take rangelock for section we need Other mechanisms that resize the shmfd grab a write lock from 0 to OFF_MAX for safety, so we still get proper synchronization of shmfd->shm_size in effect. There's no need to block readers/writers of earlier segments when we're just reserving more space, so narrow the scope -- it would likely be safe to narrow it completely to just the section of the range that extends beyond our current size, but this likely isn't worth it since the size isn't stable until the writelock is granted the first time. Suggested by: cem (passing comment) Modified: head/sys/kern/uipc_shm.c Modified: head/sys/kern/uipc_shm.c ============================================================================== --- head/sys/kern/uipc_shm.c Thu Jan 9 03:52:50 2020 (r356536) +++ head/sys/kern/uipc_shm.c Thu Jan 9 04:03:17 2020 (r356537) @@ -1451,7 +1451,17 @@ shm_fallocate(struct file *fp, off_t offset, off_t len error = 0; shmfd = fp->f_data; size = offset + len; - rl_cookie = rangelock_wlock(&shmfd->shm_rl, 0, OFF_MAX, + + /* + * Just grab the rangelock for the range that we may be attempting to + * grow, rather than blocking read/write for regions we won't be + * touching while this (potential) resize is in progress. Other + * attempts to resize the shmfd will have to take a write lock from 0 to + * OFF_MAX, so this being potentially beyond the current usable range of + * the shmfd is not necessarily a concern. If other mechanisms are + * added to grow a shmfd, this may need to be re-evaluated. + */ + rl_cookie = rangelock_wlock(&shmfd->shm_rl, offset, size, &shmfd->shm_mtx); if (size > shmfd->shm_size) { VM_OBJECT_WLOCK(shmfd->shm_object);