ypldap: reduce imsg traffic
On systems where we pull in around 100k users from ldap, ypldap uses a fair bit of memory (over 300MB peak) moving data from the ldapclient process to the main process. The ldapclient process sends each user and group record to the parent process in instances of struct idm_req, which includes a 1kB buffer for the user/group details. It currently sends the full struct through imsg, but only sending the used portion of the 1kB buffer reduces peak memory usage to around 100MB, and it turns out it's pretty easy, as in the diff below. ok? Index: ldapclient.c === RCS file: /cvs/src/usr.sbin/ypldap/ldapclient.c,v retrieving revision 1.46 diff -u -p -r1.46 ldapclient.c --- ldapclient.c13 Oct 2022 04:55:33 - 1.46 +++ ldapclient.c27 Mar 2023 04:19:53 - @@ -567,7 +567,8 @@ client_search_idm(struct env *env, struc if (client_build_req(idm, , m, min_attr, max_attr) == 0) imsg_compose_event(env->sc_iev, type, 0, 0, -1, - , sizeof(ir)); + , sizeof(ir.ir_key) + + strlen(ir.ir_line) + 1); aldap_freemsg(m); } Index: ypldap.c === RCS file: /cvs/src/usr.sbin/ypldap/ypldap.c,v retrieving revision 1.23 diff -u -p -r1.23 ypldap.c --- ypldap.c22 Aug 2022 08:02:02 - 1.23 +++ ypldap.c27 Mar 2023 04:19:53 - @@ -392,7 +392,7 @@ main_dispatch_client(int fd, short event if (env->update_trashed) break; - (void)memcpy(, imsg.data, sizeof(ir)); + (void)memcpy(, imsg.data, n - IMSG_HEADER_SIZE); if ((ue = calloc(1, sizeof(*ue))) == NULL || (ue->ue_line = strdup(ir.ir_line)) == NULL) { /* @@ -418,7 +418,7 @@ main_dispatch_client(int fd, short event if (env->update_trashed) break; - (void)memcpy(, imsg.data, sizeof(ir)); + (void)memcpy(, imsg.data, n - IMSG_HEADER_SIZE); if ((ge = calloc(1, sizeof(*ge))) == NULL || (ge->ge_line = strdup(ir.ir_line)) == NULL) { /*
head(1): Add -c argument
Hello, this is my first patch to OpenBSD. I look forward to feedback on code as well as process, communication, etc. Thank you in advance. This patch adds a -c argument to head(1). The behavior is intended to be the same as head on other systems, such as FreeBSD, NetBSD, macOS, and Linux. diff --git usr.bin/head/head.1 usr.bin/head/head.1 index 8f97660ef25..d3cb84dc462 100644 --- usr.bin/head/head.1 +++ usr.bin/head/head.1 @@ -34,17 +34,19 @@ .Os .Sh NAME .Nm head -.Nd display first few lines of files +.Nd display first few lines or bytes of files .Sh SYNOPSIS .Nm head -.Op Fl Ar count | Fl n Ar count +.Op Fl Ar count | Fl n Ar count | Fl c Ar bytes .Op Ar .Sh DESCRIPTION The .Nm utility copies the first .Ar count -lines of each specified +lines or +.Ar bytes +of each specified .Ar file to the standard output. If no files are named, @@ -63,6 +65,14 @@ lines of each input file to the standard output. .Ar count must be a positive decimal integer. .El +.Bl -tag -width Ds +.It Fl c Ar bytes +Copy the first +.Ar bytes +of each input file to the standard output. +.Ar bytes +must be a positive decimal integer. +.El .Pp If more than one file is specified, .Nm @@ -70,6 +80,12 @@ precedes the output of each file with the following, in order to distinguish files: .Pp .Dl ==> Ar file No <== +.Pp +It is an error to specify both +.Ar count +and +.Ar bytes +arguments. .Sh EXIT STATUS .Ex -std head .Sh EXAMPLES @@ -85,6 +101,13 @@ in the following way to, for example, display only line 500 from the file .Ar foo : .Pp .Dl $ head -n 500 foo | tail -1 +.Pp +.Nm +can be used in conjunction +.Xr urandom 4 +to create a random string of bytes: +.Pp +.Dl $ head -c 32 /dev/urandom | base64 .Sh SEE ALSO .Xr cat 1 , .Xr cut 1 , diff --git usr.bin/head/head.c usr.bin/head/head.c index 73670621524..1fc860929c9 100644 --- usr.bin/head/head.c +++ usr.bin/head/head.c @@ -37,7 +37,7 @@ #include #include -int head_file(const char *, long, int); +int head_file(const char *, long, long, int); static void usage(void); /* @@ -51,7 +51,8 @@ main(int argc, char *argv[]) { const char *errstr; intch; -longlinecnt = 10; +longlinecnt = -1; +longbytecnt = -1; intstatus = 0; if (pledge("stdio rpath", NULL) == -1) @@ -67,12 +68,17 @@ main(int argc, char *argv[]) argv++; } -while ((ch = getopt(argc, argv, "n:")) != -1) { +while ((ch = getopt(argc, argv, "n:c:")) != -1) { switch (ch) { case 'n': linecnt = strtonum(optarg, 1, LONG_MAX, ); if (errstr != NULL) -errx(1, "count is %s: %s", errstr, optarg); +errx(1, "line count is %s: %s", errstr, optarg); +break; +case 'c': +bytecnt = strtonum(optarg, 1, LONG_MAX, ); +if (errstr != NULL) +errx(1, "byte count is %s: %s", errstr, optarg); break; default: usage(); @@ -80,26 +86,32 @@ main(int argc, char *argv[]) } argc -= optind, argv += optind; +if (linecnt != -1 && bytecnt != -1) +errx(1, "cannot specify both line and byte counts"); +if (linecnt == -1 && bytecnt == -1) +linecnt = 10; + if (argc == 0) { if (pledge("stdio", NULL) == -1) err(1, "pledge"); -status = head_file(NULL, linecnt, 0); +status = head_file(NULL, linecnt, bytecnt, 0); } else { for (; *argv != NULL; argv++) -status |= head_file(*argv, linecnt, argc > 1); +status |= head_file(*argv, linecnt, bytecnt, argc > 1); } return status; } int -head_file(const char *path, long count, int need_header) +head_file(const char *path, long linecnt, long bytecnt, int need_header) { const char *name; FILE *fp; int ch, status = 0; static int first = 1; +long count = (linecnt != -1) ? linecnt : bytecnt; if (path != NULL) { name = path; @@ -122,7 +134,7 @@ head_file(const char *path, long count, int need_header) while ((ch = getc(fp)) != EOF) { if (putchar(ch) == EOF) err(1, "stdout"); -if (ch == '\n' && --count == 0) +if ((bytecnt != -1 || ch == '\n') && --count == 0) break; } if (ferror(fp)) { @@ -139,6 +151,6 @@ head_file(const char *path, long count, int need_header) static void usage(void) { -fputs("usage: head [-count | -n count] [file ...]\n", stderr); +fputs("usage: head [-count | -n count | -c bytes] [file ...]\n", stderr); exit(1); }
Re: installer: apple arm64: simplify firmware copy
On Sat, Mar 25, 2023 at 06:38:56PM +, Klemens Nanni wrote: > Less duplicate code, simpler to cope with newer firmware. > Same idiom is used in install.sub already. > > OK? While unlikely to fail, I do prefer `cd ... && ...` as a general rule. However, this definitely makes it easier to tell that we're doing the same thing. OK afresh1@ > Index: ramdisk/install.md > === > RCS file: /cvs/src/distrib/arm64/ramdisk/install.md,v > retrieving revision 1.37 > diff -u -p -r1.37 install.md > --- ramdisk/install.md25 Mar 2023 18:29:37 - 1.37 > +++ ramdisk/install.md25 Mar 2023 18:35:52 - > @@ -55,14 +55,9 @@ md_installboot() { > > case $_plat in > apple) > - if [[ -d /etc/firmware/apple ]]; then > - (cd /etc/firmware > - pax -rw apple /mnt/etc/firmware) > - fi > - if [[ -d /etc/firmware/apple-bwfm ]]; then > - (cd /etc/firmware > - pax -rw apple-bwfm /mnt/etc/firmware) > - fi > + (cd /etc/firmware; for _dir in apple{,-bwfm}; do > + [[ -d $_dir ]] && pax -rw $_dir /mnt/etc/firmware > + done) > ;; > pine64) > dd if=$_mdec/u-boot-sunxi-with-spl.bin of=${_disk}c \ >
Re: unifdef ath(4)
On Sun, Mar 26, 2023 at 05:17:36PM +1100, Jonathan Gray wrote: > there is no need to sync with FreeBSD ok stsp > Index: sys/dev/ic/ath.c > === > RCS file: /cvs/src/sys/dev/ic/ath.c,v > retrieving revision 1.123 > diff -u -p -r1.123 ath.c > --- sys/dev/ic/ath.c 21 Apr 2022 21:03:02 - 1.123 > +++ sys/dev/ic/ath.c 26 Mar 2023 06:00:43 - > @@ -308,11 +308,6 @@ ath_attach(u_int16_t devid, struct ath_s > timeout_set(>sc_cal_to, ath_calibrate, sc); > timeout_set(>sc_rssadapt_to, ath_rssadapt_updatestats, sc); > > -#ifdef __FreeBSD__ > - ATH_TXBUF_LOCK_INIT(sc); > - ATH_TXQ_LOCK_INIT(sc); > -#endif > - > ATH_TASK_INIT(>sc_txtask, ath_tx_proc, sc); > ATH_TASK_INIT(>sc_rxtask, ath_rx_proc, sc); > ATH_TASK_INIT(>sc_rxorntask, ath_rxorn_proc, sc); > @@ -352,9 +347,6 @@ ath_attach(u_int16_t devid, struct ath_s > ifp->if_start = ath_start; > ifp->if_watchdog = ath_watchdog; > ifp->if_ioctl = ath_ioctl; > -#ifndef __OpenBSD__ > - ifp->if_stop = ath_stop;/* XXX */ > -#endif > ifq_set_maxlen(>if_snd, ATH_TXBUF * ATH_TXDESC); > > ic->ic_softc = sc; > @@ -472,10 +464,6 @@ ath_detach(struct ath_softc *sc, int fla > if_detach(ifp); > > splx(s); > -#ifdef __FreeBSD__ > - ATH_TXBUF_LOCK_DESTROY(sc); > - ATH_TXQ_LOCK_DESTROY(sc); > -#endif > > return 0; > } > @@ -983,15 +971,6 @@ ath_ioctl(struct ifnet *ifp, u_long cmd, > break; > case SIOCADDMULTI: > case SIOCDELMULTI: > -#ifdef __FreeBSD__ > - /* > - * The upper layer has already installed/removed > - * the multicast address(es), just recalculate the > - * multicast filter for the card. > - */ > - if (ifp->if_flags & IFF_RUNNING) > - ath_mode_init(sc); > -#endif > error = (cmd == SIOCADDMULTI) ? > ether_addmulti(ifr, >sc_ic.ic_ac) : > ether_delmulti(ifr, >sc_ic.ic_ac); > @@ -1189,13 +1168,6 @@ ath_getmbuf(int flags, int type, u_int p > struct mbuf *m; > > KASSERT(pktlen <= MCLBYTES, ("802.11 packet too large: %u", pktlen)); > -#ifdef __FreeBSD__ > - if (pktlen <= MHLEN) { > - MGETHDR(m, flags, type); > - } else { > - m = m_getcl(flags, type, M_PKTHDR); > - } > -#else > MGETHDR(m, flags, type); > if (m != NULL && pktlen > MHLEN) { > MCLGET(m, flags); > @@ -1204,7 +1176,6 @@ ath_getmbuf(int flags, int type, u_int p > m = NULL; > } > } > -#endif > return m; > } > > Index: sys/dev/ic/athvar.h > === > RCS file: /cvs/src/sys/dev/ic/athvar.h,v > retrieving revision 1.35 > diff -u -p -r1.35 athvar.h > --- sys/dev/ic/athvar.h 11 Oct 2020 07:05:28 - 1.35 > +++ sys/dev/ic/athvar.h 26 Mar 2023 05:19:55 - > @@ -194,15 +194,11 @@ typedef struct ath_task { > } ath_task_t; > > struct ath_softc { > -#ifndef __FreeBSD__ > struct device sc_dev; > -#endif > struct ieee80211com sc_ic; /* IEEE 802.11 common */ > -#ifndef __FreeBSD__ > int (*sc_enable)(struct ath_softc *); > void(*sc_disable)(struct ath_softc *); > void(*sc_power)(struct ath_softc *, int); > -#endif > int (*sc_newstate)(struct ieee80211com *, > enum ieee80211_state, int); > void(*sc_node_free)(struct ieee80211com *, > @@ -213,16 +209,10 @@ struct ath_softc { > void(*sc_recv_mgmt)(struct ieee80211com *, > struct mbuf *, struct ieee80211_node *, > struct ieee80211_rxinfo *, int); > -#ifdef __FreeBSD__ > - device_tsc_dev; > -#endif > bus_space_tag_t sc_st; /* bus space tag */ > bus_space_handle_t sc_sh; /* bus space handle */ > bus_size_t sc_ss; /* bus space size */ > bus_dma_tag_t sc_dmat;/* bus DMA tag */ > -#ifdef __FreeBSD__ > - struct mtx sc_mtx; /* master lock (recursive) */ > -#endif > struct ath_hal *sc_ah; /* Atheros HAL */ > unsigned intsc_invalid : 1, /* disable hardware accesses */ > sc_doani : 1, /* dynamic noise immunity */ > @@ -274,13 +264,7 @@ struct ath_softc { > u_int32_t *sc_txlink; /* link ptr in last TX desc */ > int sc_tx_timer;/* transmit timeout */ > TAILQ_HEAD(, ath_buf) sc_txbuf; /* transmit buffer */ > -#ifdef __FreeBSD__ > - struct mtx
Re: Patch to stop tearing on Intel modesetting in Xenocara
Ok, thank you for explanation. In that case let's wait. Thanks, Igor. On Sun 26 Mar 2023, 08:10 Matthieu Herrb, wrote: > On Sat, Mar 25, 2023 at 09:58:31PM +, Igor Petruk wrote: > > Hi, > > > > I noticed the "TearFree" patch was merged upstream in the XOrg > > modesetting driver. Long time ago when it was sent I patched it into > > my local Xenocara and used it ever since. Zero issues, zero tearing. > > > > Maybe let's consider adding it to Xenocara too? I am attaching the > > patch, commit message is from my local git repo, I am of course NOT an > > author. It adds the "TearFree" option to the modesetting section of > > your xorg.conf. > > > > Feel free to fetch it directly from the Merge Request, the real author > > is https://gitlab.freedesktop.org/kerneltoast: > > > > https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1006 > > > > I am just sending this as is, but I don't know enough about XOrg to > > follow up with extra fixes to the code. I can only confirm that it > > worked flawlessly on my Intel NUC 11 for a really long time. > > > > Thanks, > > Igor. > > Hi, > > This will be merged in OpenBSD sometime after the next major X server > version (based on the current main branch of the gitlab repository) > will be released. > > We try to avoid merging parts of the main branch because it then makes > merging full releases more complex. > > -- > Matthieu Herrb >
Re: Patch to stop tearing on Intel modesetting in Xenocara
On Sat, Mar 25, 2023 at 09:58:31PM +, Igor Petruk wrote: > Hi, > > I noticed the "TearFree" patch was merged upstream in the XOrg > modesetting driver. Long time ago when it was sent I patched it into > my local Xenocara and used it ever since. Zero issues, zero tearing. > > Maybe let's consider adding it to Xenocara too? I am attaching the > patch, commit message is from my local git repo, I am of course NOT an > author. It adds the "TearFree" option to the modesetting section of > your xorg.conf. > > Feel free to fetch it directly from the Merge Request, the real author > is https://gitlab.freedesktop.org/kerneltoast: > > https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1006 > > I am just sending this as is, but I don't know enough about XOrg to > follow up with extra fixes to the code. I can only confirm that it > worked flawlessly on my Intel NUC 11 for a really long time. > > Thanks, > Igor. Hi, This will be merged in OpenBSD sometime after the next major X server version (based on the current main branch of the gitlab repository) will be released. We try to avoid merging parts of the main branch because it then makes merging full releases more complex. -- Matthieu Herrb
unifdef ath(4)
there is no need to sync with FreeBSD Index: sys/dev/ic/ath.c === RCS file: /cvs/src/sys/dev/ic/ath.c,v retrieving revision 1.123 diff -u -p -r1.123 ath.c --- sys/dev/ic/ath.c21 Apr 2022 21:03:02 - 1.123 +++ sys/dev/ic/ath.c26 Mar 2023 06:00:43 - @@ -308,11 +308,6 @@ ath_attach(u_int16_t devid, struct ath_s timeout_set(>sc_cal_to, ath_calibrate, sc); timeout_set(>sc_rssadapt_to, ath_rssadapt_updatestats, sc); -#ifdef __FreeBSD__ - ATH_TXBUF_LOCK_INIT(sc); - ATH_TXQ_LOCK_INIT(sc); -#endif - ATH_TASK_INIT(>sc_txtask, ath_tx_proc, sc); ATH_TASK_INIT(>sc_rxtask, ath_rx_proc, sc); ATH_TASK_INIT(>sc_rxorntask, ath_rxorn_proc, sc); @@ -352,9 +347,6 @@ ath_attach(u_int16_t devid, struct ath_s ifp->if_start = ath_start; ifp->if_watchdog = ath_watchdog; ifp->if_ioctl = ath_ioctl; -#ifndef __OpenBSD__ - ifp->if_stop = ath_stop;/* XXX */ -#endif ifq_set_maxlen(>if_snd, ATH_TXBUF * ATH_TXDESC); ic->ic_softc = sc; @@ -472,10 +464,6 @@ ath_detach(struct ath_softc *sc, int fla if_detach(ifp); splx(s); -#ifdef __FreeBSD__ - ATH_TXBUF_LOCK_DESTROY(sc); - ATH_TXQ_LOCK_DESTROY(sc); -#endif return 0; } @@ -983,15 +971,6 @@ ath_ioctl(struct ifnet *ifp, u_long cmd, break; case SIOCADDMULTI: case SIOCDELMULTI: -#ifdef __FreeBSD__ - /* -* The upper layer has already installed/removed -* the multicast address(es), just recalculate the -* multicast filter for the card. -*/ - if (ifp->if_flags & IFF_RUNNING) - ath_mode_init(sc); -#endif error = (cmd == SIOCADDMULTI) ? ether_addmulti(ifr, >sc_ic.ic_ac) : ether_delmulti(ifr, >sc_ic.ic_ac); @@ -1189,13 +1168,6 @@ ath_getmbuf(int flags, int type, u_int p struct mbuf *m; KASSERT(pktlen <= MCLBYTES, ("802.11 packet too large: %u", pktlen)); -#ifdef __FreeBSD__ - if (pktlen <= MHLEN) { - MGETHDR(m, flags, type); - } else { - m = m_getcl(flags, type, M_PKTHDR); - } -#else MGETHDR(m, flags, type); if (m != NULL && pktlen > MHLEN) { MCLGET(m, flags); @@ -1204,7 +1176,6 @@ ath_getmbuf(int flags, int type, u_int p m = NULL; } } -#endif return m; } Index: sys/dev/ic/athvar.h === RCS file: /cvs/src/sys/dev/ic/athvar.h,v retrieving revision 1.35 diff -u -p -r1.35 athvar.h --- sys/dev/ic/athvar.h 11 Oct 2020 07:05:28 - 1.35 +++ sys/dev/ic/athvar.h 26 Mar 2023 05:19:55 - @@ -194,15 +194,11 @@ typedef struct ath_task { } ath_task_t; struct ath_softc { -#ifndef __FreeBSD__ struct device sc_dev; -#endif struct ieee80211com sc_ic; /* IEEE 802.11 common */ -#ifndef __FreeBSD__ int (*sc_enable)(struct ath_softc *); void(*sc_disable)(struct ath_softc *); void(*sc_power)(struct ath_softc *, int); -#endif int (*sc_newstate)(struct ieee80211com *, enum ieee80211_state, int); void(*sc_node_free)(struct ieee80211com *, @@ -213,16 +209,10 @@ struct ath_softc { void(*sc_recv_mgmt)(struct ieee80211com *, struct mbuf *, struct ieee80211_node *, struct ieee80211_rxinfo *, int); -#ifdef __FreeBSD__ - device_tsc_dev; -#endif bus_space_tag_t sc_st; /* bus space tag */ bus_space_handle_t sc_sh; /* bus space handle */ bus_size_t sc_ss; /* bus space size */ bus_dma_tag_t sc_dmat;/* bus DMA tag */ -#ifdef __FreeBSD__ - struct mtx sc_mtx; /* master lock (recursive) */ -#endif struct ath_hal *sc_ah; /* Atheros HAL */ unsigned intsc_invalid : 1, /* disable hardware accesses */ sc_doani : 1, /* dynamic noise immunity */ @@ -274,13 +264,7 @@ struct ath_softc { u_int32_t *sc_txlink; /* link ptr in last TX desc */ int sc_tx_timer;/* transmit timeout */ TAILQ_HEAD(, ath_buf) sc_txbuf; /* transmit buffer */ -#ifdef __FreeBSD__ - struct mtx sc_txbuflock; /* txbuf lock */ -#endif TAILQ_HEAD(, ath_buf) sc_txq; /* transmitting queue */ -#ifdef __FreeBSD__ - struct mtx sc_txqlock; /* lock on